First, the imports


In [1]:
from pandas import DataFrame, Series
import pandas as pd

Next, load the data:


In [4]:
stations = pd.read_table("stations.tsv")
usage = pd.read_table("usage_2012.tsv")
weather = pd.read_table("daily_weather.tsv")

Average temperature by season


In [5]:
weather.columns


Out[5]:
Index([u'date', u'weekday', u'season_code', u'season_desc', u'is_holiday', u'is_work_day', u'weather_code', u'weather_desc', u'temp', u'subjective_temp', u'humidity', u'windspeed', u'no_casual_riders', u'no_reg_riders', u'total_riders'], dtype='object')

In [6]:
weather.head


Out[6]:
<bound method DataFrame.head of            date  weekday  season_code season_desc  is_holiday  is_work_day  \
0    2012-01-01        0            1      Spring           0            0   
1    2012-01-02        1            1      Spring           1            0   
2    2012-01-03        2            1      Spring           0            1   
3    2012-01-04        3            1      Spring           0            1   
4    2012-01-05        4            1      Spring           0            1   
5    2012-01-06        5            1      Spring           0            1   
6    2012-01-07        6            1      Spring           0            0   
7    2012-01-08        0            1      Spring           0            0   
8    2012-01-09        1            1      Spring           0            1   
9    2012-01-10        2            1      Spring           0            1   
10   2012-01-11        3            1      Spring           0            1   
11   2012-01-12        4            1      Spring           0            1   
12   2012-01-13        5            1      Spring           0            1   
13   2012-01-14        6            1      Spring           0            0   
14   2012-01-15        0            1      Spring           0            0   
15   2012-01-16        1            1      Spring           1            0   
16   2012-01-17        2            1      Spring           0            1   
17   2012-01-18        3            1      Spring           0            1   
18   2012-01-19        4            1      Spring           0            1   
19   2012-01-20        5            1      Spring           0            1   
20   2012-01-21        6            1      Spring           0            0   
21   2012-01-22        0            1      Spring           0            0   
22   2012-01-23        1            1      Spring           0            1   
23   2012-01-24        2            1      Spring           0            1   
24   2012-01-25        3            1      Spring           0            1   
25   2012-01-26        4            1      Spring           0            1   
26   2012-01-27        5            1      Spring           0            1   
27   2012-01-28        6            1      Spring           0            0   
28   2012-01-29        0            1      Spring           0            0   
29   2012-01-30        1            1      Spring           0            1   
..          ...      ...          ...         ...         ...          ...   
336  2012-12-02        0            4      Winter           0            0   
337  2012-12-03        1            4      Winter           0            1   
338  2012-12-04        2            4      Winter           0            1   
339  2012-12-05        3            4      Winter           0            1   
340  2012-12-06        4            4      Winter           0            1   
341  2012-12-07        5            4      Winter           0            1   
342  2012-12-08        6            4      Winter           0            0   
343  2012-12-09        0            4      Winter           0            0   
344  2012-12-10        1            4      Winter           0            1   
345  2012-12-11        2            4      Winter           0            1   
346  2012-12-12        3            4      Winter           0            1   
347  2012-12-13        4            4      Winter           0            1   
348  2012-12-14        5            4      Winter           0            1   
349  2012-12-15        6            4      Winter           0            0   
350  2012-12-16        0            4      Winter           0            0   
351  2012-12-17        1            4      Winter           0            1   
352  2012-12-18        2            4      Winter           0            1   
353  2012-12-19        3            4      Winter           0            1   
354  2012-12-20        4            4      Winter           0            1   
355  2012-12-21        5            1      Spring           0            1   
356  2012-12-22        6            1      Spring           0            0   
357  2012-12-23        0            1      Spring           0            0   
358  2012-12-24        1            1      Spring           0            1   
359  2012-12-25        2            1      Spring           1            0   
360  2012-12-26        3            1      Spring           0            1   
361  2012-12-27        4            1      Spring           0            1   
362  2012-12-28        5            1      Spring           0            1   
363  2012-12-29        6            1      Spring           0            0   
364  2012-12-30        0            1      Spring           0            0   
365  2012-12-31        1            1      Spring           0            1   

     weather_code                                       weather_desc  \
0               1    Clear, Few clouds, Partly cloudy, Partly cloudy   
1               1    Clear, Few clouds, Partly cloudy, Partly cloudy   
2               1    Clear, Few clouds, Partly cloudy, Partly cloudy   
3               2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
4               1    Clear, Few clouds, Partly cloudy, Partly cloudy   
5               1    Clear, Few clouds, Partly cloudy, Partly cloudy   
6               1    Clear, Few clouds, Partly cloudy, Partly cloudy   
7               1    Clear, Few clouds, Partly cloudy, Partly cloudy   
8               2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
9               1    Clear, Few clouds, Partly cloudy, Partly cloudy   
10              2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
11              2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
12              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
13              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
14              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
15              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
16              2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
17              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
18              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
19              2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
20              2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
21              2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
22              2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
23              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
24              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
25              2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
26              2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
27              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
28              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
29              1    Clear, Few clouds, Partly cloudy, Partly cloudy   
..            ...                                                ...   
336             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
337             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
338             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
339             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
340             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
341             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
342             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
343             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
344             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
345             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
346             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
347             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
348             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
349             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
350             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
351             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
352             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
353             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
354             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
355             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
356             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
357             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
358             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
359             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
360             3  Light Snow, Light Rain + Thunderstorm + Scatte...   
361             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
362             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
363             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   
364             1    Clear, Few clouds, Partly cloudy, Partly cloudy   
365             2  Mist + Cloudy, Mist + Broken clouds, Mist + Fe...   

         temp  subjective_temp  humidity  windspeed  no_casual_riders  \
0    0.370000         0.375621  0.692500   0.192167               686   
1    0.273043         0.252304  0.381304   0.329665               244   
2    0.150000         0.126275  0.441250   0.365671                89   
3    0.107500         0.119337  0.414583   0.184700                95   
4    0.265833         0.278412  0.524167   0.129987               140   
5    0.334167         0.340267  0.542083   0.167908               307   
6    0.393333         0.390779  0.531667   0.174758              1070   
7    0.337500         0.340258  0.465000   0.191542               599   
8    0.224167         0.247479  0.701667   0.098900               106   
9    0.308696         0.318826  0.646522   0.187552               173   
10   0.274167         0.282821  0.847500   0.131221                92   
11   0.382500         0.381938  0.802917   0.180967               269   
12   0.274167         0.249362  0.507500   0.378108               174   
13   0.180000         0.183087  0.457500   0.187183               333   
14   0.166667         0.161625  0.419167   0.251258               284   
15   0.190000         0.190663  0.522500   0.231358               217   
16   0.373043         0.364278  0.716087   0.349130               127   
17   0.303333         0.275254  0.443333   0.415429               109   
18   0.190000         0.190038  0.497500   0.220158               130   
19   0.217500         0.220958  0.450000   0.202750               115   
20   0.173333         0.174875  0.831250   0.222642                67   
21   0.162500         0.162250  0.796250   0.199638               196   
22   0.218333         0.243058  0.911250   0.110708               145   
23   0.342500         0.349108  0.835833   0.123767               439   
24   0.294167         0.294821  0.643750   0.161071               467   
25   0.341667         0.356050  0.769583   0.073396               244   
26   0.425000         0.415383  0.741250   0.342667               269   
27   0.315833         0.326379  0.543333   0.210829               775   
28   0.282500         0.272721  0.311250   0.240050               558   
29   0.269167         0.262625  0.400833   0.215792               126   
..        ...              ...       ...        ...               ...   
336  0.347500         0.359208  0.823333   0.124379               892   
337  0.452500         0.455796  0.767500   0.082721               555   
338  0.475833         0.469054  0.733750   0.174129               551   
339  0.438333         0.428012  0.485000   0.324021               331   
340  0.255833         0.258204  0.508750   0.174754               340   
341  0.320833         0.321958  0.764167   0.130600               349   
342  0.381667         0.389508  0.911250   0.101379              1153   
343  0.384167         0.390146  0.905417   0.157975               441   
344  0.435833         0.435575  0.925000   0.190308               329   
345  0.353333         0.338363  0.596667   0.296037               282   
346  0.297500         0.297338  0.538333   0.162937               310   
347  0.295833         0.294188  0.485833   0.174129               425   
348  0.281667         0.294192  0.642917   0.131229               429   
349  0.324167         0.338383  0.650417   0.106350               767   
350  0.362500         0.369938  0.838750   0.100742               538   
351  0.393333         0.401500  0.907083   0.098258               212   
352  0.410833         0.409708  0.666250   0.221404               433   
353  0.332500         0.342162  0.625417   0.184092               333   
354  0.330000         0.335217  0.667917   0.132463               314   
355  0.326667         0.301767  0.556667   0.374383               221   
356  0.265833         0.236113  0.441250   0.407346               205   
357  0.245833         0.259471  0.515417   0.133083               408   
358  0.231304         0.258900  0.791304   0.077230               174   
359  0.291304         0.294465  0.734783   0.168726               440   
360  0.243333         0.220333  0.823333   0.316546                 9   
361  0.254167         0.226642  0.652917   0.350133               247   
362  0.253333         0.255046  0.590000   0.155471               644   
363  0.253333         0.242400  0.752917   0.124383               159   
364  0.255833         0.231700  0.483333   0.350754               364   
365  0.215833         0.223487  0.577500   0.154846               439   

     no_reg_riders  total_riders  
0             1608          2294  
1             1707          1951  
2             2147          2236  
3             2273          2368  
4             3132          3272  
5             3791          4098  
6             3451          4521  
7             2826          3425  
8             2270          2376  
9             3425          3598  
10            2085          2177  
11            3828          4097  
12            3040          3214  
13            2160          2493  
14            2027          2311  
15            2081          2298  
16            2808          2935  
17            3267          3376  
18            3162          3292  
19            3048          3163  
20            1234          1301  
21            1781          1977  
22            2287          2432  
23            3900          4339  
24            3803          4270  
25            3831          4075  
26            3187          3456  
27            3248          4023  
28            2685          3243  
29            3498          3624  
..             ...           ...  
336           3757          4649  
337           5679          6234  
338           6055          6606  
339           5398          5729  
340           5035          5375  
341           4659          5008  
342           4429          5582  
343           2787          3228  
344           4841          5170  
345           5219          5501  
346           5009          5319  
347           5107          5532  
348           5182          5611  
349           4280          5047  
350           3248          3786  
351           4373          4585  
352           5124          5557  
353           4934          5267  
354           3814          4128  
355           3402          3623  
356           1544          1749  
357           1379          1787  
358            746           920  
359            573          1013  
360            432           441  
361           1867          2114  
362           2451          3095  
363           1182          1341  
364           1432          1796  
365           2290          2729  

[366 rows x 15 columns]>

In [7]:
weather.groupby('season_desc')['temp'].mean()


Out[7]:
season_desc
Fall           0.711445
Spring         0.321700
Summer         0.554557
Winter         0.419368
Name: temp, dtype: float64

What's wrong with the seasons?


In [8]:
weather.groupby('season_desc')['date'].agg(['min', 'max'])


Out[8]:
min max
season_desc
Fall 2012-06-21 2012-09-22
Spring 2012-01-01 2012-12-31
Summer 2012-03-21 2012-06-20
Winter 2012-09-23 2012-12-20

off by one!


In [9]:
season_remap = { "Fall" : "Summer", "Summer" : "Spring", "Spring" : "Winter", "Winter" : "Fall" }

In [21]:
weather['season_desc'] = weather['season_desc'].apply(season_remap.get)

In [22]:
weather.groupby('season_desc')['temp'].mean()


Out[22]:
season_desc
Fall           0.419368
Spring         0.554557
Summer         0.711445
Winter         0.321700
Name: temp, dtype: float64

Fix Dates


In [23]:
weather.date


Out[23]:
0     2012-01-01
1     2012-01-02
2     2012-01-03
3     2012-01-04
4     2012-01-05
5     2012-01-06
6     2012-01-07
7     2012-01-08
8     2012-01-09
9     2012-01-10
10    2012-01-11
11    2012-01-12
12    2012-01-13
13    2012-01-14
14    2012-01-15
...
351    2012-12-17
352    2012-12-18
353    2012-12-19
354    2012-12-20
355    2012-12-21
356    2012-12-22
357    2012-12-23
358    2012-12-24
359    2012-12-25
360    2012-12-26
361    2012-12-27
362    2012-12-28
363    2012-12-29
364    2012-12-30
365    2012-12-31
Name: date, Length: 366, dtype: object

In [24]:
pd.to_datetime(weather.date)


Out[24]:
0    2012-01-01
1    2012-01-02
2    2012-01-03
3    2012-01-04
4    2012-01-05
5    2012-01-06
6    2012-01-07
7    2012-01-08
8    2012-01-09
9    2012-01-10
10   2012-01-11
11   2012-01-12
12   2012-01-13
13   2012-01-14
14   2012-01-15
...
351   2012-12-17
352   2012-12-18
353   2012-12-19
354   2012-12-20
355   2012-12-21
356   2012-12-22
357   2012-12-23
358   2012-12-24
359   2012-12-25
360   2012-12-26
361   2012-12-27
362   2012-12-28
363   2012-12-29
364   2012-12-30
365   2012-12-31
Name: date, Length: 366, dtype: datetime64[ns]

In [25]:
weather['date'] = pd.to_datetime(weather.date)

In [26]:
usage.columns


Out[26]:
Index([u'bike_id', u'time_start', u'time_end', u'duration_mins', u'station_start', u'station_end', u'cust_type'], dtype='object')

In [27]:
usage['time_start'] = pd.to_datetime(usage.time_start)

In [28]:
usage['time_end'] = pd.to_datetime(usage.time_end)

In [29]:
usage.time_start


Out[29]:
0    2012-01-01 00:04:00
1    2012-01-01 00:10:00
2    2012-01-01 00:10:00
3    2012-01-01 00:15:00
4    2012-01-01 00:15:00
5    2012-01-01 00:17:00
6    2012-01-01 00:18:00
7    2012-01-01 00:22:00
8    2012-01-01 00:24:00
9    2012-01-01 00:25:00
10   2012-01-01 00:29:00
11   2012-01-01 00:30:00
12   2012-01-01 00:32:00
13   2012-01-01 00:32:00
14   2012-01-01 00:33:00
...
2412509   2012-12-31 09:05:00
2412510   2012-12-31 09:05:00
2412511   2012-12-31 09:04:00
2412512   2012-12-31 09:04:00
2412513   2012-12-31 09:02:00
2412514   2012-12-31 09:02:00
2412515   2012-12-31 09:02:00
2412516   2012-12-31 09:02:00
2412517   2012-12-31 09:01:00
2412518   2012-12-31 09:01:00
2412519   2012-12-31 09:01:00
2412520   2012-12-31 09:01:00
2412521   2012-12-31 09:00:00
2412522   2012-12-31 09:00:00
2412523   2012-12-31 09:00:00
Name: time_start, Length: 2412524, dtype: datetime64[ns]

In [33]:
usage.time_start.dt.month


Out[33]:
0     1
1     1
2     1
3     1
4     1
5     1
6     1
7     1
8     1
9     1
10    1
11    1
12    1
13    1
14    1
...
2412509    12
2412510    12
2412511    12
2412512    12
2412513    12
2412514    12
2412515    12
2412516    12
2412517    12
2412518    12
2412519    12
2412520    12
2412521    12
2412522    12
2412523    12
Length: 2412524, dtype: int64

In [40]:
usage.time_start.dt.month.value_counts()


Out[40]:
3     329308
9     218573
8     214503
2     205958
7     203607
6     202600
10    198841
5     195638
1     193180
4     173954
11    152649
12    123713
dtype: int64

Rentals v Temperature


In [41]:
weather.columns


Out[41]:
Index([u'date', u'weekday', u'season_code', u'season_desc', u'is_holiday', u'is_work_day', u'weather_code', u'weather_desc', u'temp', u'subjective_temp', u'humidity', u'windspeed', u'no_casual_riders', u'no_reg_riders', u'total_riders'], dtype='object')

In [42]:
weather['month'] = weather.date.dt.month

In [43]:
weather.groupby('month')['total_riders'].sum()


Out[43]:
month
1         96744
2        103137
3        164875
4        174224
5        195865
6        202830
7        203607
8        214503
9        218573
10       198841
11       152664
12       123713
Name: total_riders, dtype: int64

In [44]:
temps = weather['temp']

In [75]:
temps.index = weather.date.apply(lambda x: x.date())

In [76]:
temps


Out[76]:
date
2012-01-01    0.370000
2012-01-02    0.273043
2012-01-03    0.150000
2012-01-04    0.107500
2012-01-05    0.265833
2012-01-06    0.334167
2012-01-07    0.393333
2012-01-08    0.337500
2012-01-09    0.224167
2012-01-10    0.308696
2012-01-11    0.274167
2012-01-12    0.382500
2012-01-13    0.274167
2012-01-14    0.180000
2012-01-15    0.166667
...
2012-12-17    0.393333
2012-12-18    0.410833
2012-12-19    0.332500
2012-12-20    0.330000
2012-12-21    0.326667
2012-12-22    0.265833
2012-12-23    0.245833
2012-12-24    0.231304
2012-12-25    0.291304
2012-12-26    0.243333
2012-12-27    0.254167
2012-12-28    0.253333
2012-12-29    0.253333
2012-12-30    0.255833
2012-12-31    0.215833
Name: temp, Length: 366, dtype: float64

In [77]:
temp_dict = temps.to_dict()

In [78]:
temp_dict


Out[78]:
{datetime.date(2012, 1, 1): 0.37,
 datetime.date(2012, 1, 2): 0.27304299999999998,
 datetime.date(2012, 1, 3): 0.14999999999999999,
 datetime.date(2012, 1, 4): 0.1075,
 datetime.date(2012, 1, 5): 0.26583299999999999,
 datetime.date(2012, 1, 6): 0.33416699999999999,
 datetime.date(2012, 1, 7): 0.39333299999999999,
 datetime.date(2012, 1, 8): 0.33750000000000002,
 datetime.date(2012, 1, 9): 0.22416700000000001,
 datetime.date(2012, 1, 10): 0.30869600000000003,
 datetime.date(2012, 1, 11): 0.27416699999999999,
 datetime.date(2012, 1, 12): 0.38250000000000001,
 datetime.date(2012, 1, 13): 0.27416699999999999,
 datetime.date(2012, 1, 14): 0.17999999999999999,
 datetime.date(2012, 1, 15): 0.16666700000000001,
 datetime.date(2012, 1, 16): 0.19,
 datetime.date(2012, 1, 17): 0.37304299999999996,
 datetime.date(2012, 1, 18): 0.30333300000000002,
 datetime.date(2012, 1, 19): 0.19,
 datetime.date(2012, 1, 20): 0.2175,
 datetime.date(2012, 1, 21): 0.17333299999999999,
 datetime.date(2012, 1, 22): 0.16250000000000001,
 datetime.date(2012, 1, 23): 0.218333,
 datetime.date(2012, 1, 24): 0.34250000000000003,
 datetime.date(2012, 1, 25): 0.29416700000000001,
 datetime.date(2012, 1, 26): 0.341667,
 datetime.date(2012, 1, 27): 0.42499999999999999,
 datetime.date(2012, 1, 28): 0.31583299999999997,
 datetime.date(2012, 1, 29): 0.28249999999999997,
 datetime.date(2012, 1, 30): 0.26916699999999999,
 datetime.date(2012, 1, 31): 0.39000000000000001,
 datetime.date(2012, 2, 1): 0.469167,
 datetime.date(2012, 2, 2): 0.39916699999999999,
 datetime.date(2012, 2, 3): 0.31333299999999997,
 datetime.date(2012, 2, 4): 0.26416699999999999,
 datetime.date(2012, 2, 5): 0.26583299999999999,
 datetime.date(2012, 2, 6): 0.282609,
 datetime.date(2012, 2, 7): 0.35416700000000001,
 datetime.date(2012, 2, 8): 0.25666700000000003,
 datetime.date(2012, 2, 9): 0.26500000000000001,
 datetime.date(2012, 2, 10): 0.280833,
 datetime.date(2012, 2, 11): 0.22416700000000001,
 datetime.date(2012, 2, 12): 0.1275,
 datetime.date(2012, 2, 13): 0.2225,
 datetime.date(2012, 2, 14): 0.31916700000000003,
 datetime.date(2012, 2, 15): 0.348333,
 datetime.date(2012, 2, 16): 0.31666700000000003,
 datetime.date(2012, 2, 17): 0.343333,
 datetime.date(2012, 2, 18): 0.346667,
 datetime.date(2012, 2, 19): 0.28000000000000003,
 datetime.date(2012, 2, 20): 0.28000000000000003,
 datetime.date(2012, 2, 21): 0.28782600000000003,
 datetime.date(2012, 2, 22): 0.39583299999999999,
 datetime.date(2012, 2, 23): 0.45416699999999999,
 datetime.date(2012, 2, 24): 0.40749999999999997,
 datetime.date(2012, 2, 25): 0.29083300000000001,
 datetime.date(2012, 2, 26): 0.279167,
 datetime.date(2012, 2, 27): 0.36666700000000002,
 datetime.date(2012, 2, 28): 0.35916700000000001,
 datetime.date(2012, 2, 29): 0.34434799999999999,
 datetime.date(2012, 3, 1): 0.48583300000000001,
 datetime.date(2012, 3, 2): 0.35333300000000001,
 datetime.date(2012, 3, 3): 0.41416700000000001,
 datetime.date(2012, 3, 4): 0.32583299999999998,
 datetime.date(2012, 3, 5): 0.24333299999999999,
 datetime.date(2012, 3, 6): 0.25833299999999998,
 datetime.date(2012, 3, 7): 0.404167,
 datetime.date(2012, 3, 8): 0.52749999999999997,
 datetime.date(2012, 3, 9): 0.410833,
 datetime.date(2012, 3, 10): 0.28749999999999998,
 datetime.date(2012, 3, 11): 0.36173899999999998,
 datetime.date(2012, 3, 12): 0.466667,
 datetime.date(2012, 3, 13): 0.56499999999999995,
 datetime.date(2012, 3, 14): 0.57250000000000001,
 datetime.date(2012, 3, 15): 0.5575,
 datetime.date(2012, 3, 16): 0.43583299999999997,
 datetime.date(2012, 3, 17): 0.51416700000000004,
 datetime.date(2012, 3, 18): 0.47249999999999998,
 datetime.date(2012, 3, 19): 0.54500000000000004,
 datetime.date(2012, 3, 20): 0.56083300000000003,
 datetime.date(2012, 3, 21): 0.531667,
 datetime.date(2012, 3, 22): 0.55416699999999997,
 datetime.date(2012, 3, 23): 0.60166699999999995,
 datetime.date(2012, 3, 24): 0.50249999999999995,
 datetime.date(2012, 3, 25): 0.4375,
 datetime.date(2012, 3, 26): 0.44583299999999998,
 datetime.date(2012, 3, 27): 0.32333299999999998,
 datetime.date(2012, 3, 28): 0.48416700000000001,
 datetime.date(2012, 3, 29): 0.49416700000000002,
 datetime.date(2012, 3, 30): 0.37,
 datetime.date(2012, 3, 31): 0.42416700000000002,
 datetime.date(2012, 4, 1): 0.42583300000000002,
 datetime.date(2012, 4, 2): 0.43391299999999999,
 datetime.date(2012, 4, 3): 0.466667,
 datetime.date(2012, 4, 4): 0.54166700000000001,
 datetime.date(2012, 4, 5): 0.435,
 datetime.date(2012, 4, 6): 0.403333,
 datetime.date(2012, 4, 7): 0.4375,
 datetime.date(2012, 4, 8): 0.5,
 datetime.date(2012, 4, 9): 0.48916700000000002,
 datetime.date(2012, 4, 10): 0.44666699999999998,
 datetime.date(2012, 4, 11): 0.34869600000000001,
 datetime.date(2012, 4, 12): 0.39750000000000002,
 datetime.date(2012, 4, 13): 0.4425,
 datetime.date(2012, 4, 14): 0.495,
 datetime.date(2012, 4, 15): 0.60666699999999996,
 datetime.date(2012, 4, 16): 0.66416699999999995,
 datetime.date(2012, 4, 17): 0.60833300000000001,
 datetime.date(2012, 4, 18): 0.46333299999999999,
 datetime.date(2012, 4, 19): 0.49833299999999997,
 datetime.date(2012, 4, 20): 0.526667,
 datetime.date(2012, 4, 21): 0.56999999999999995,
 datetime.date(2012, 4, 22): 0.39666699999999999,
 datetime.date(2012, 4, 23): 0.32166699999999998,
 datetime.date(2012, 4, 24): 0.41333300000000001,
 datetime.date(2012, 4, 25): 0.47666700000000001,
 datetime.date(2012, 4, 26): 0.49833299999999997,
 datetime.date(2012, 4, 27): 0.45750000000000002,
 datetime.date(2012, 4, 28): 0.37666700000000003,
 datetime.date(2012, 4, 29): 0.45833299999999999,
 datetime.date(2012, 4, 30): 0.464167,
 datetime.date(2012, 5, 1): 0.61333300000000002,
 datetime.date(2012, 5, 2): 0.56416699999999997,
 datetime.date(2012, 5, 3): 0.56000000000000005,
 datetime.date(2012, 5, 4): 0.62749999999999995,
 datetime.date(2012, 5, 5): 0.62166699999999997,
 datetime.date(2012, 5, 6): 0.5625,
 datetime.date(2012, 5, 7): 0.53749999999999998,
 datetime.date(2012, 5, 8): 0.58166700000000005,
 datetime.date(2012, 5, 9): 0.57499999999999996,
 datetime.date(2012, 5, 10): 0.50583299999999998,
 datetime.date(2012, 5, 11): 0.53333299999999995,
 datetime.date(2012, 5, 12): 0.56416699999999997,
 datetime.date(2012, 5, 13): 0.61250000000000004,
 datetime.date(2012, 5, 14): 0.57333299999999998,
 datetime.date(2012, 5, 15): 0.61166699999999996,
 datetime.date(2012, 5, 16): 0.63666699999999998,
 datetime.date(2012, 5, 17): 0.593333,
 datetime.date(2012, 5, 18): 0.56416699999999997,
 datetime.date(2012, 5, 19): 0.59999999999999998,
 datetime.date(2012, 5, 20): 0.62083299999999997,
 datetime.date(2012, 5, 21): 0.598333,
 datetime.date(2012, 5, 22): 0.61499999999999999,
 datetime.date(2012, 5, 23): 0.62166699999999997,
 datetime.date(2012, 5, 24): 0.65500000000000003,
 datetime.date(2012, 5, 25): 0.68000000000000005,
 datetime.date(2012, 5, 26): 0.6925,
 datetime.date(2012, 5, 27): 0.68999999999999995,
 datetime.date(2012, 5, 28): 0.71250000000000002,
 datetime.date(2012, 5, 29): 0.72250000000000003,
 datetime.date(2012, 5, 30): 0.656667,
 datetime.date(2012, 5, 31): 0.68000000000000005,
 datetime.date(2012, 6, 1): 0.65416700000000005,
 datetime.date(2012, 6, 2): 0.58333299999999999,
 datetime.date(2012, 6, 3): 0.60250000000000004,
 datetime.date(2012, 6, 4): 0.59750000000000003,
 datetime.date(2012, 6, 5): 0.54083300000000001,
 datetime.date(2012, 6, 6): 0.55416699999999997,
 datetime.date(2012, 6, 7): 0.60250000000000004,
 datetime.date(2012, 6, 8): 0.64916700000000005,
 datetime.date(2012, 6, 9): 0.71083300000000005,
 datetime.date(2012, 6, 10): 0.72666699999999995,
 datetime.date(2012, 6, 11): 0.72083299999999995,
 datetime.date(2012, 6, 12): 0.65333299999999994,
 datetime.date(2012, 6, 13): 0.655833,
 datetime.date(2012, 6, 14): 0.64833300000000005,
 datetime.date(2012, 6, 15): 0.63916700000000004,
 datetime.date(2012, 6, 16): 0.63166699999999998,
 datetime.date(2012, 6, 17): 0.59250000000000003,
 datetime.date(2012, 6, 18): 0.56833299999999998,
 datetime.date(2012, 6, 19): 0.68833299999999997,
 datetime.date(2012, 6, 20): 0.78249999999999997,
 datetime.date(2012, 6, 21): 0.80583300000000002,
 datetime.date(2012, 6, 22): 0.77749999999999997,
 datetime.date(2012, 6, 23): 0.73166699999999996,
 datetime.date(2012, 6, 24): 0.74333300000000002,
 datetime.date(2012, 6, 25): 0.71583299999999994,
 datetime.date(2012, 6, 26): 0.63083299999999998,
 datetime.date(2012, 6, 27): 0.69750000000000001,
 datetime.date(2012, 6, 28): 0.74916700000000003,
 datetime.date(2012, 6, 29): 0.83416699999999999,
 datetime.date(2012, 6, 30): 0.76500000000000001,
 datetime.date(2012, 7, 1): 0.81583300000000003,
 datetime.date(2012, 7, 2): 0.781667,
 datetime.date(2012, 7, 3): 0.780833,
 datetime.date(2012, 7, 4): 0.78916699999999995,
 datetime.date(2012, 7, 5): 0.82750000000000001,
 datetime.date(2012, 7, 6): 0.82833299999999999,
 datetime.date(2012, 7, 7): 0.86166699999999996,
 datetime.date(2012, 7, 8): 0.82250000000000001,
 datetime.date(2012, 7, 9): 0.71083300000000005,
 datetime.date(2012, 7, 10): 0.72083299999999995,
 datetime.date(2012, 7, 11): 0.71666700000000005,
 datetime.date(2012, 7, 12): 0.71583299999999994,
 datetime.date(2012, 7, 13): 0.73166699999999996,
 datetime.date(2012, 7, 14): 0.70333299999999999,
 datetime.date(2012, 7, 15): 0.74583299999999997,
 datetime.date(2012, 7, 16): 0.76333300000000004,
 datetime.date(2012, 7, 17): 0.81833299999999998,
 datetime.date(2012, 7, 18): 0.79333299999999995,
 datetime.date(2012, 7, 19): 0.77000000000000002,
 datetime.date(2012, 7, 20): 0.66583300000000001,
 datetime.date(2012, 7, 21): 0.59583299999999995,
 datetime.date(2012, 7, 22): 0.66749999999999998,
 datetime.date(2012, 7, 23): 0.74166699999999997,
 datetime.date(2012, 7, 24): 0.75083299999999997,
 datetime.date(2012, 7, 25): 0.72416700000000001,
 datetime.date(2012, 7, 26): 0.776667,
 datetime.date(2012, 7, 27): 0.781667,
 datetime.date(2012, 7, 28): 0.75583299999999998,
 datetime.date(2012, 7, 29): 0.72166700000000006,
 datetime.date(2012, 7, 30): 0.73083299999999995,
 datetime.date(2012, 7, 31): 0.71333299999999999,
 datetime.date(2012, 8, 1): 0.71750000000000003,
 datetime.date(2012, 8, 2): 0.75249999999999995,
 datetime.date(2012, 8, 3): 0.76583299999999999,
 datetime.date(2012, 8, 4): 0.79333299999999995,
 datetime.date(2012, 8, 5): 0.76916700000000005,
 datetime.date(2012, 8, 6): 0.75249999999999995,
 datetime.date(2012, 8, 7): 0.73583299999999996,
 datetime.date(2012, 8, 8): 0.75,
 datetime.date(2012, 8, 9): 0.75583299999999998,
 datetime.date(2012, 8, 10): 0.71583299999999994,
 datetime.date(2012, 8, 11): 0.6925,
 datetime.date(2012, 8, 12): 0.70083300000000004,
 datetime.date(2012, 8, 13): 0.72083299999999995,
 datetime.date(2012, 8, 14): 0.72666699999999995,
 datetime.date(2012, 8, 15): 0.70666700000000005,
 datetime.date(2012, 8, 16): 0.719167,
 datetime.date(2012, 8, 17): 0.723333,
 datetime.date(2012, 8, 18): 0.67833299999999996,
 datetime.date(2012, 8, 19): 0.63583299999999998,
 datetime.date(2012, 8, 20): 0.63583299999999998,
 datetime.date(2012, 8, 21): 0.64916700000000005,
 datetime.date(2012, 8, 22): 0.66749999999999998,
 datetime.date(2012, 8, 23): 0.69583300000000003,
 datetime.date(2012, 8, 24): 0.70250000000000001,
 datetime.date(2012, 8, 25): 0.66166700000000001,
 datetime.date(2012, 8, 26): 0.65333299999999994,
 datetime.date(2012, 8, 27): 0.70333299999999999,
 datetime.date(2012, 8, 28): 0.72833300000000001,
 datetime.date(2012, 8, 29): 0.68500000000000005,
 datetime.date(2012, 8, 30): 0.70666700000000005,
 datetime.date(2012, 8, 31): 0.76416700000000004,
 datetime.date(2012, 9, 1): 0.75333300000000003,
 datetime.date(2012, 9, 2): 0.69666700000000004,
 datetime.date(2012, 9, 3): 0.70750000000000002,
 datetime.date(2012, 9, 4): 0.72583299999999995,
 datetime.date(2012, 9, 5): 0.73666699999999996,
 datetime.date(2012, 9, 6): 0.69666700000000004,
 datetime.date(2012, 9, 7): 0.70333299999999999,
 datetime.date(2012, 9, 8): 0.65916700000000006,
 datetime.date(2012, 9, 9): 0.60999999999999999,
 datetime.date(2012, 9, 10): 0.58333299999999999,
 datetime.date(2012, 9, 11): 0.57750000000000001,
 datetime.date(2012, 9, 12): 0.59916700000000001,
 datetime.date(2012, 9, 13): 0.61250000000000004,
 datetime.date(2012, 9, 14): 0.63333300000000003,
 datetime.date(2012, 9, 15): 0.60833300000000001,
 datetime.date(2012, 9, 16): 0.57999999999999996,
 datetime.date(2012, 9, 17): 0.58083300000000004,
 datetime.date(2012, 9, 18): 0.62333300000000003,
 datetime.date(2012, 9, 19): 0.55249999999999999,
 datetime.date(2012, 9, 20): 0.54666700000000001,
 datetime.date(2012, 9, 21): 0.59916700000000001,
 datetime.date(2012, 9, 22): 0.65000000000000002,
 datetime.date(2012, 9, 23): 0.52916700000000005,
 datetime.date(2012, 9, 24): 0.51416700000000004,
 datetime.date(2012, 9, 25): 0.55000000000000004,
 datetime.date(2012, 9, 26): 0.63500000000000001,
 datetime.date(2012, 9, 27): 0.65000000000000002,
 datetime.date(2012, 9, 28): 0.61916700000000002,
 datetime.date(2012, 9, 29): 0.54249999999999998,
 datetime.date(2012, 9, 30): 0.526667,
 datetime.date(2012, 10, 1): 0.52083299999999999,
 datetime.date(2012, 10, 2): 0.59083299999999994,
 datetime.date(2012, 10, 3): 0.65749999999999997,
 datetime.date(2012, 10, 4): 0.65749999999999997,
 datetime.date(2012, 10, 5): 0.61499999999999999,
 datetime.date(2012, 10, 6): 0.55416699999999997,
 datetime.date(2012, 10, 7): 0.41583300000000001,
 datetime.date(2012, 10, 8): 0.38333299999999998,
 datetime.date(2012, 10, 9): 0.44666699999999998,
 datetime.date(2012, 10, 10): 0.51416700000000004,
 datetime.date(2012, 10, 11): 0.435,
 datetime.date(2012, 10, 12): 0.4375,
 datetime.date(2012, 10, 13): 0.39333299999999999,
 datetime.date(2012, 10, 14): 0.52166699999999999,
 datetime.date(2012, 10, 15): 0.56166700000000003,
 datetime.date(2012, 10, 16): 0.468333,
 datetime.date(2012, 10, 17): 0.45583299999999999,
 datetime.date(2012, 10, 18): 0.52249999999999996,
 datetime.date(2012, 10, 19): 0.56333299999999997,
 datetime.date(2012, 10, 20): 0.48416700000000001,
 datetime.date(2012, 10, 21): 0.464167,
 datetime.date(2012, 10, 22): 0.48749999999999999,
 datetime.date(2012, 10, 23): 0.54416699999999996,
 datetime.date(2012, 10, 24): 0.58750000000000002,
 datetime.date(2012, 10, 25): 0.55000000000000004,
 datetime.date(2012, 10, 26): 0.54583300000000001,
 datetime.date(2012, 10, 27): 0.53000000000000003,
 datetime.date(2012, 10, 28): 0.47749999999999998,
 datetime.date(2012, 10, 29): 0.44,
 datetime.date(2012, 10, 30): 0.31818200000000002,
 datetime.date(2012, 10, 31): 0.35749999999999998,
 datetime.date(2012, 11, 1): 0.36583300000000002,
 datetime.date(2012, 11, 2): 0.35499999999999998,
 datetime.date(2012, 11, 3): 0.343333,
 datetime.date(2012, 11, 4): 0.32583299999999998,
 datetime.date(2012, 11, 5): 0.31916700000000003,
 datetime.date(2012, 11, 6): 0.280833,
 datetime.date(2012, 11, 7): 0.29583300000000001,
 datetime.date(2012, 11, 8): 0.35217399999999999,
 datetime.date(2012, 11, 9): 0.36166700000000002,
 datetime.date(2012, 11, 10): 0.38916699999999999,
 datetime.date(2012, 11, 11): 0.42083300000000001,
 datetime.date(2012, 11, 12): 0.48499999999999999,
 datetime.date(2012, 11, 13): 0.343333,
 datetime.date(2012, 11, 14): 0.28916700000000001,
 datetime.date(2012, 11, 15): 0.32166699999999998,
 datetime.date(2012, 11, 16): 0.34499999999999997,
 datetime.date(2012, 11, 17): 0.32500000000000001,
 datetime.date(2012, 11, 18): 0.34250000000000003,
 datetime.date(2012, 11, 19): 0.38083299999999998,
 datetime.date(2012, 11, 20): 0.37416700000000003,
 datetime.date(2012, 11, 21): 0.35333300000000001,
 datetime.date(2012, 11, 22): 0.34000000000000002,
 datetime.date(2012, 11, 23): 0.36833299999999997,
 datetime.date(2012, 11, 24): 0.278333,
 datetime.date(2012, 11, 25): 0.245833,
 datetime.date(2012, 11, 26): 0.31333299999999997,
 datetime.date(2012, 11, 27): 0.29166700000000001,
 datetime.date(2012, 11, 28): 0.29666700000000001,
 datetime.date(2012, 11, 29): 0.28087000000000001,
 datetime.date(2012, 11, 30): 0.29833300000000001,
 datetime.date(2012, 12, 1): 0.29833300000000001,
 datetime.date(2012, 12, 2): 0.34749999999999998,
 datetime.date(2012, 12, 3): 0.45250000000000001,
 datetime.date(2012, 12, 4): 0.47583300000000001,
 datetime.date(2012, 12, 5): 0.43833299999999997,
 datetime.date(2012, 12, 6): 0.25583299999999998,
 datetime.date(2012, 12, 7): 0.32083299999999998,
 datetime.date(2012, 12, 8): 0.38166700000000003,
 datetime.date(2012, 12, 9): 0.38416699999999998,
 datetime.date(2012, 12, 10): 0.43583299999999997,
 datetime.date(2012, 12, 11): 0.35333300000000001,
 datetime.date(2012, 12, 12): 0.29749999999999999,
 datetime.date(2012, 12, 13): 0.29583300000000001,
 datetime.date(2012, 12, 14): 0.281667,
 datetime.date(2012, 12, 15): 0.32416699999999998,
 datetime.date(2012, 12, 16): 0.36249999999999999,
 datetime.date(2012, 12, 17): 0.39333299999999999,
 datetime.date(2012, 12, 18): 0.410833,
 datetime.date(2012, 12, 19): 0.33250000000000002,
 datetime.date(2012, 12, 20): 0.33000000000000002,
 datetime.date(2012, 12, 21): 0.32666699999999999,
 datetime.date(2012, 12, 22): 0.26583299999999999,
 datetime.date(2012, 12, 23): 0.245833,
 datetime.date(2012, 12, 24): 0.23130400000000001,
 datetime.date(2012, 12, 25): 0.29130400000000001,
 datetime.date(2012, 12, 26): 0.24333299999999999,
 datetime.date(2012, 12, 27): 0.25416700000000003,
 datetime.date(2012, 12, 28): 0.25333299999999997,
 datetime.date(2012, 12, 29): 0.25333299999999997,
 datetime.date(2012, 12, 30): 0.25583299999999998,
 datetime.date(2012, 12, 31): 0.215833}

In [83]:
usage['date'] = usage['time_start'].apply(lambda x: x.date())

In [90]:
rentals_by_date = usage.groupby('date')['bike_id'].count()

In [91]:
rentals_by_date


Out[91]:
date
2012-01-01    4588
2012-01-02    3900
2012-01-03    4466
2012-01-04    4734
2012-01-05    6538
2012-01-06    8182
2012-01-07    9040
2012-01-08    6848
2012-01-09    4740
2012-01-10    7184
2012-01-11    4348
2012-01-12    8182
2012-01-13    6414
2012-01-14    4982
2012-01-15    4612
...
2012-12-17    4585
2012-12-18    5557
2012-12-19    5267
2012-12-20    4128
2012-12-21    3623
2012-12-22    1749
2012-12-23    1787
2012-12-24     920
2012-12-25    1013
2012-12-26     441
2012-12-27    2114
2012-12-28    3095
2012-12-29    1341
2012-12-30    1796
2012-12-31    2729
Name: bike_id, Length: 366, dtype: int64

In [92]:
counts_and_weather = DataFrame({"rentals" : rentals_by_date, "temp" : temps})

In [93]:
counts_and_weather


Out[93]:
rentals temp
date
2012-01-01 4588 0.370000
2012-01-02 3900 0.273043
2012-01-03 4466 0.150000
2012-01-04 4734 0.107500
2012-01-05 6538 0.265833
2012-01-06 8182 0.334167
2012-01-07 9040 0.393333
2012-01-08 6848 0.337500
2012-01-09 4740 0.224167
2012-01-10 7184 0.308696
2012-01-11 4348 0.274167
2012-01-12 8182 0.382500
2012-01-13 6414 0.274167
2012-01-14 4982 0.180000
2012-01-15 4612 0.166667
2012-01-16 4590 0.190000
2012-01-17 5862 0.373043
2012-01-18 6740 0.303333
2012-01-19 6570 0.190000
2012-01-20 6312 0.217500
2012-01-21 2600 0.173333
2012-01-22 3950 0.162500
2012-01-23 4858 0.218333
2012-01-24 8654 0.342500
2012-01-25 8518 0.294167
2012-01-26 8120 0.341667
2012-01-27 6898 0.425000
2012-01-28 8038 0.315833
2012-01-29 6480 0.282500
2012-01-30 7230 0.269167
... ... ...
2012-12-02 4649 0.347500
2012-12-03 6234 0.452500
2012-12-04 6606 0.475833
2012-12-05 5729 0.438333
2012-12-06 5375 0.255833
2012-12-07 5008 0.320833
2012-12-08 5582 0.381667
2012-12-09 3228 0.384167
2012-12-10 5170 0.435833
2012-12-11 5501 0.353333
2012-12-12 5319 0.297500
2012-12-13 5532 0.295833
2012-12-14 5611 0.281667
2012-12-15 5047 0.324167
2012-12-16 3786 0.362500
2012-12-17 4585 0.393333
2012-12-18 5557 0.410833
2012-12-19 5267 0.332500
2012-12-20 4128 0.330000
2012-12-21 3623 0.326667
2012-12-22 1749 0.265833
2012-12-23 1787 0.245833
2012-12-24 920 0.231304
2012-12-25 1013 0.291304
2012-12-26 441 0.243333
2012-12-27 2114 0.254167
2012-12-28 3095 0.253333
2012-12-29 1341 0.253333
2012-12-30 1796 0.255833
2012-12-31 2729 0.215833

366 rows × 2 columns


In [94]:
counts_and_weather.corr()


Out[94]:
rentals temp
rentals 1.000000 0.272782
temp 0.272782 1.000000

In [96]:
weather.index = weather.date

In [97]:
weather


Out[97]:
date weekday season_code season_desc is_holiday is_work_day weather_code weather_desc temp subjective_temp humidity windspeed no_casual_riders no_reg_riders total_riders month
date
2012-01-01 2012-01-01 0 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.370000 0.375621 0.692500 0.192167 686 1608 2294 1
2012-01-02 2012-01-02 1 1 Winter 1 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.273043 0.252304 0.381304 0.329665 244 1707 1951 1
2012-01-03 2012-01-03 2 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.150000 0.126275 0.441250 0.365671 89 2147 2236 1
2012-01-04 2012-01-04 3 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.107500 0.119337 0.414583 0.184700 95 2273 2368 1
2012-01-05 2012-01-05 4 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.265833 0.278412 0.524167 0.129987 140 3132 3272 1
2012-01-06 2012-01-06 5 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.334167 0.340267 0.542083 0.167908 307 3791 4098 1
2012-01-07 2012-01-07 6 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.393333 0.390779 0.531667 0.174758 1070 3451 4521 1
2012-01-08 2012-01-08 0 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.337500 0.340258 0.465000 0.191542 599 2826 3425 1
2012-01-09 2012-01-09 1 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.224167 0.247479 0.701667 0.098900 106 2270 2376 1
2012-01-10 2012-01-10 2 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.308696 0.318826 0.646522 0.187552 173 3425 3598 1
2012-01-11 2012-01-11 3 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.274167 0.282821 0.847500 0.131221 92 2085 2177 1
2012-01-12 2012-01-12 4 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.382500 0.381938 0.802917 0.180967 269 3828 4097 1
2012-01-13 2012-01-13 5 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.274167 0.249362 0.507500 0.378108 174 3040 3214 1
2012-01-14 2012-01-14 6 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.180000 0.183087 0.457500 0.187183 333 2160 2493 1
2012-01-15 2012-01-15 0 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.166667 0.161625 0.419167 0.251258 284 2027 2311 1
2012-01-16 2012-01-16 1 1 Winter 1 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.190000 0.190663 0.522500 0.231358 217 2081 2298 1
2012-01-17 2012-01-17 2 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.373043 0.364278 0.716087 0.349130 127 2808 2935 1
2012-01-18 2012-01-18 3 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.303333 0.275254 0.443333 0.415429 109 3267 3376 1
2012-01-19 2012-01-19 4 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.190000 0.190038 0.497500 0.220158 130 3162 3292 1
2012-01-20 2012-01-20 5 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.217500 0.220958 0.450000 0.202750 115 3048 3163 1
2012-01-21 2012-01-21 6 1 Winter 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.173333 0.174875 0.831250 0.222642 67 1234 1301 1
2012-01-22 2012-01-22 0 1 Winter 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.162500 0.162250 0.796250 0.199638 196 1781 1977 1
2012-01-23 2012-01-23 1 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.218333 0.243058 0.911250 0.110708 145 2287 2432 1
2012-01-24 2012-01-24 2 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.342500 0.349108 0.835833 0.123767 439 3900 4339 1
2012-01-25 2012-01-25 3 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.294167 0.294821 0.643750 0.161071 467 3803 4270 1
2012-01-26 2012-01-26 4 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.341667 0.356050 0.769583 0.073396 244 3831 4075 1
2012-01-27 2012-01-27 5 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.425000 0.415383 0.741250 0.342667 269 3187 3456 1
2012-01-28 2012-01-28 6 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.315833 0.326379 0.543333 0.210829 775 3248 4023 1
2012-01-29 2012-01-29 0 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.282500 0.272721 0.311250 0.240050 558 2685 3243 1
2012-01-30 2012-01-30 1 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.269167 0.262625 0.400833 0.215792 126 3498 3624 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2012-12-02 2012-12-02 0 4 Fall 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.347500 0.359208 0.823333 0.124379 892 3757 4649 12
2012-12-03 2012-12-03 1 4 Fall 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.452500 0.455796 0.767500 0.082721 555 5679 6234 12
2012-12-04 2012-12-04 2 4 Fall 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.475833 0.469054 0.733750 0.174129 551 6055 6606 12
2012-12-05 2012-12-05 3 4 Fall 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.438333 0.428012 0.485000 0.324021 331 5398 5729 12
2012-12-06 2012-12-06 4 4 Fall 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.255833 0.258204 0.508750 0.174754 340 5035 5375 12
2012-12-07 2012-12-07 5 4 Fall 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.320833 0.321958 0.764167 0.130600 349 4659 5008 12
2012-12-08 2012-12-08 6 4 Fall 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.381667 0.389508 0.911250 0.101379 1153 4429 5582 12
2012-12-09 2012-12-09 0 4 Fall 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.384167 0.390146 0.905417 0.157975 441 2787 3228 12
2012-12-10 2012-12-10 1 4 Fall 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.435833 0.435575 0.925000 0.190308 329 4841 5170 12
2012-12-11 2012-12-11 2 4 Fall 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.353333 0.338363 0.596667 0.296037 282 5219 5501 12
2012-12-12 2012-12-12 3 4 Fall 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.297500 0.297338 0.538333 0.162937 310 5009 5319 12
2012-12-13 2012-12-13 4 4 Fall 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.295833 0.294188 0.485833 0.174129 425 5107 5532 12
2012-12-14 2012-12-14 5 4 Fall 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.281667 0.294192 0.642917 0.131229 429 5182 5611 12
2012-12-15 2012-12-15 6 4 Fall 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.324167 0.338383 0.650417 0.106350 767 4280 5047 12
2012-12-16 2012-12-16 0 4 Fall 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.362500 0.369938 0.838750 0.100742 538 3248 3786 12
2012-12-17 2012-12-17 1 4 Fall 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.393333 0.401500 0.907083 0.098258 212 4373 4585 12
2012-12-18 2012-12-18 2 4 Fall 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.410833 0.409708 0.666250 0.221404 433 5124 5557 12
2012-12-19 2012-12-19 3 4 Fall 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.332500 0.342162 0.625417 0.184092 333 4934 5267 12
2012-12-20 2012-12-20 4 4 Fall 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.330000 0.335217 0.667917 0.132463 314 3814 4128 12
2012-12-21 2012-12-21 5 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.326667 0.301767 0.556667 0.374383 221 3402 3623 12
2012-12-22 2012-12-22 6 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.265833 0.236113 0.441250 0.407346 205 1544 1749 12
2012-12-23 2012-12-23 0 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.245833 0.259471 0.515417 0.133083 408 1379 1787 12
2012-12-24 2012-12-24 1 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.231304 0.258900 0.791304 0.077230 174 746 920 12
2012-12-25 2012-12-25 2 1 Winter 1 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.291304 0.294465 0.734783 0.168726 440 573 1013 12
2012-12-26 2012-12-26 3 1 Winter 0 1 3 Light Snow, Light Rain + Thunderstorm + Scatte... 0.243333 0.220333 0.823333 0.316546 9 432 441 12
2012-12-27 2012-12-27 4 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.254167 0.226642 0.652917 0.350133 247 1867 2114 12
2012-12-28 2012-12-28 5 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.253333 0.255046 0.590000 0.155471 644 2451 3095 12
2012-12-29 2012-12-29 6 1 Winter 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.253333 0.242400 0.752917 0.124383 159 1182 1341 12
2012-12-30 2012-12-30 0 1 Winter 0 0 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.255833 0.231700 0.483333 0.350754 364 1432 1796 12
2012-12-31 2012-12-31 1 1 Winter 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.215833 0.223487 0.577500 0.154846 439 2290 2729 12

366 rows × 16 columns


In [99]:
weather['counts'] = rentals_by_date

In [100]:
weather[['counts', 'temp']].corr()


Out[100]:
counts temp
counts 1.000000 0.272782
temp 0.272782 1.000000

In [101]:
weather[['counts', 'temp']][weather['season_desc'] == 'Summer'].corr()


Out[101]:
counts temp
counts 1.000000 -0.326098
temp -0.326098 1.000000

In [102]:
weather[['counts', 'temp']][weather['season_desc'] == 'Winter'].corr()


Out[102]:
counts temp
counts 1.000000 0.778723
temp 0.778723 1.000000

In [103]:
weather[['counts', 'temp']][weather['season_desc'] == 'Spring'].corr()


Out[103]:
counts temp
counts 1.000000 -0.008046
temp -0.008046 1.000000

In [104]:
weather[['counts', 'temp']][weather['season_desc'] == 'Fall'].corr()


Out[104]:
counts temp
counts 1.000000 0.626595
temp 0.626595 1.000000

Visualization


In [106]:
%matplotlib inline

In [ ]:


In [110]:
weather[['temp', 'humidity']].plot()


Out[110]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f399a62d110>

In [113]:
weather.groupby('month')[['temp', 'humidity']].mean().plot(kind='bar')


Out[113]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f3998e18c50>

In [115]:
import matplotlib.pyplot as plt

In [116]:
plt.scatter(weather['temp'], weather['humidity'])


Out[116]:
<matplotlib.collections.PathCollection at 0x7f3997fcfb90>

In [117]:
plt.scatter(weather['temp'], weather['counts'])


Out[117]:
<matplotlib.collections.PathCollection at 0x7f3997f479d0>

In [119]:
for season, color in zip(['Winter', 'Spring', 'Summer', 'Fall'], ['b', 'g', 'r', 'y']):
    plt.scatter(weather['temp'][weather.season_desc == season], weather['counts'][weather.season_desc == season], label=season, color=color)
plt.legend()


Out[119]:
<matplotlib.legend.Legend at 0x7f3997eb0850>

In [121]:
weather[weather['counts'] > 10000]


Out[121]:
date weekday season_code season_desc is_holiday is_work_day weather_code weather_desc temp subjective_temp humidity windspeed no_casual_riders no_reg_riders total_riders month counts
date
2012-02-23 2012-02-23 4 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.454167 0.444446 0.554583 0.190913 516 4546 5062 2 10096
2012-03-08 2012-03-08 4 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.527500 0.524604 0.567500 0.441563 486 4896 5382 3 10748
2012-03-12 2012-03-12 1 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.466667 0.459592 0.489167 0.207713 838 4460 5298 3 10580
2012-03-13 2012-03-13 2 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.565000 0.542929 0.617500 0.236950 762 5085 5847 3 11666
2012-03-14 2012-03-14 3 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.572500 0.548617 0.507083 0.115062 997 5315 6312 3 12610
2012-03-15 2012-03-15 4 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.557500 0.532825 0.579583 0.149883 1005 5187 6192 3 12366
2012-03-17 2012-03-17 6 1 Winter 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.514167 0.505046 0.755833 0.110704 3155 4681 7836 3 15664
2012-03-18 2012-03-18 0 1 Winter 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.472500 0.464000 0.810000 0.126883 2207 3685 5892 3 11780
2012-03-19 2012-03-19 1 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.545000 0.532821 0.728750 0.162317 982 5171 6153 3 12292
2012-03-20 2012-03-20 2 1 Winter 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.560833 0.538533 0.807917 0.121271 1051 5042 6093 3 12176
2012-03-21 2012-03-21 3 2 Spring 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.531667 0.513258 0.821250 0.089558 1122 5108 6230 3 12442
2012-03-22 2012-03-22 4 2 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.554167 0.531567 0.831250 0.117562 1334 5537 6871 3 13718
2012-03-23 2012-03-23 5 2 Spring 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.601667 0.570067 0.694167 0.116300 2469 5893 8362 3 16702
2012-03-26 2012-03-26 1 2 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.445833 0.438750 0.477917 0.386821 795 4763 5558 3 11098
2012-03-27 2012-03-27 2 2 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.323333 0.315654 0.290000 0.187192 531 4571 5102 3 10186
2012-03-28 2012-03-28 3 2 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.484167 0.470950 0.481250 0.291671 674 5024 5698 3 11384
2012-03-29 2012-03-29 4 2 Spring 0 1 1 Clear, Few clouds, Partly cloudy, Partly cloudy 0.494167 0.482304 0.439167 0.319650 834 5299 6133 3 12252
2012-03-30 2012-03-30 5 2 Spring 0 1 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.370000 0.375621 0.580833 0.138067 796 4663 5459 3 10894
2012-03-31 2012-03-31 6 2 Spring 0 0 2 Mist + Cloudy, Mist + Broken clouds, Mist + Fe... 0.424167 0.421708 0.738333 0.250617 2301 3934 6235 3 12466

In [122]:
stations


Out[122]:
id station terminal_name lat long no_bikes no_empty_docks fast_food parking restaurant ... museum sculpture hostel picnic_site tour_guide attraction landmark motel guest_house gallery
0 1 20th & Bell St 31000 38.856100 -77.051200 7 4 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
1 2 18th & Eads St. 31001 38.857250 -77.053320 6 4 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
2 3 20th & Crystal Dr 31002 38.856400 -77.049200 9 6 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
3 4 15th & Crystal Dr 31003 38.860170 -77.049593 4 6 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
4 5 Aurora Hills Community Ctr/18th & Hayes St 31004 38.857866 -77.059490 5 5 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
5 6 Pentagon City Metro / 12th & S Hayes St 31005 38.862303 -77.059936 8 11 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
6 7 S Joyce & Army Navy Dr 31006 38.863700 -77.063300 7 3 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
7 8 Crystal City Metro / 18th & Bell St 31007 38.857300 -77.051100 11 7 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
8 9 12th & Army Navy Dr 31008 38.862900 -77.052800 3 7 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
9 10 27th & Crystal Dr 31009 38.848441 -77.051516 6 13 0 0 1 ... 0 0 0 0 0 0 0 0 0 0
10 11 S Glebe & Potomac Ave 31010 38.842600 -77.050200 4 7 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
11 12 23rd & Crystal Dr 31011 38.853300 -77.049800 5 11 4 1 13 ... 0 0 0 0 0 0 0 0 0 0
12 13 26th & S Clark St 31012 38.850688 -77.051520 8 3 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
13 14 19th St & Pennsylvania Ave NW 31100 38.900300 -77.042900 10 4 8 6 13 ... 0 0 0 0 0 0 0 0 0 0
14 15 14th & V St NW 31101 38.917600 -77.032100 23 2 5 0 13 ... 0 0 0 0 0 0 0 0 0 0
15 16 11th & Kenyon St NW 31102 38.929464 -77.027822 6 21 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
16 17 16th & Harvard St NW 31103 38.926088 -77.036536 4 28 1 0 0 ... 0 0 0 0 0 0 0 0 0 0
17 18 Adams Mill & Columbia Rd NW 31104 38.922925 -77.042581 0 13 7 0 21 ... 0 0 0 0 0 0 0 0 0 0
18 19 14th & Harvard St NW 31105 38.926800 -77.032200 2 17 2 0 3 ... 0 0 0 0 0 0 0 0 0 0
19 20 Calvert & Biltmore St NW 31106 38.923203 -77.047637 2 21 0 0 1 ... 0 0 0 0 0 0 0 0 0 0
20 21 Lamont & Mt Pleasant NW 31107 38.931900 -77.038800 1 18 0 0 7 ... 0 0 0 0 0 0 0 0 0 0
21 22 4th & M St SW 31108 38.876700 -77.017800 22 0 2 0 2 ... 0 0 0 0 0 0 0 0 0 0
22 23 15th & P St NW 31201 38.909850 -77.034438 13 3 3 0 8 ... 0 0 0 0 0 0 0 0 0 0
23 24 14th & R St NW 31202 38.912682 -77.031681 14 1 0 0 7 ... 0 0 0 0 0 0 0 0 0 0
24 25 14th & Rhode Island Ave NW 31203 38.908600 -77.032300 22 0 2 0 10 ... 1 0 0 0 0 0 0 0 0 0
25 26 20th & E St NW 31204 38.896300 -77.045000 5 10 3 1 0 ... 0 0 0 0 0 0 0 0 0 0
26 27 21st & I St NW 31205 38.900800 -77.047000 21 14 3 8 6 ... 0 0 0 0 0 0 0 0 0 0
27 28 Georgia & New Hampshire Ave NW 31400 38.936043 -77.024649 10 5 1 0 4 ... 0 0 0 0 0 0 0 0 0 0
28 29 14th St & Spring Rd NW 31401 38.937500 -77.032800 0 10 0 0 16 ... 0 0 0 0 0 0 0 0 0 0
29 30 John McCormack Dr & Michigan Ave NE 31502 38.934600 -76.995500 8 2 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
317 327 Rockville Metro West 32047 39.084379 -77.146866 11 8 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
318 328 Bethesda Metro 32048 38.984691 -77.094537 4 8 1 2 3 ... 0 0 0 0 0 0 0 0 0 0
319 329 Iwo Jima Memorial/N Meade & 14th St N 31077 38.889920 -77.071301 8 10 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
320 330 34th & Water St NW 31314 38.903582 -77.067786 7 11 1 0 5 ... 0 0 0 0 0 1 0 0 0 1
321 331 Duke St & John Carlyle St 31081 38.804378 -77.060866 9 6 4 5 2 ... 0 0 0 0 0 0 1 0 0 0
322 332 Lee Hwy & N Cleveland St 31079 38.894941 -77.091690 6 9 1 0 0 ... 0 0 0 0 0 0 0 0 0 0
323 333 Arlington Blvd & S George Mason Dr/NFATC 31078 38.869442 -77.104503 6 5 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
324 334 MLK Library/9th & G St NW 31274 38.898404 -77.024281 8 14 8 2 19 ... 4 0 0 0 0 0 0 0 0 0
325 335 Lee Hwy & N Scott St 31080 38.897612 -77.080851 10 5 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
326 336 New Hampshire Ave & 24th St NW 31275 38.901755 -77.051084 6 9 0 2 9 ... 0 0 0 0 0 0 0 0 0 0
327 337 Eisenhower Ave & Mill Race Ln 31082 38.801111 -77.068952 10 4 1 1 2 ... 0 0 0 0 0 0 0 0 0 0
328 338 Potomac Greens Dr & Slaters Ln 31083 38.821750 -77.047494 7 4 1 0 2 ... 0 0 0 0 0 0 0 0 0 0
329 339 Ballenger Ave & Dulaney St 31084 38.802677 -77.063562 8 11 2 4 3 ... 0 0 0 0 0 1 0 0 0 0
330 340 Mount Vernon Ave & E Nelson Ave 31085 38.820064 -77.057619 4 7 0 0 4 ... 0 0 0 0 0 0 0 0 0 0
331 341 Mount Vernon Ave & E Del Ray Ave 31086 38.825950 -77.058541 7 8 0 0 3 ... 0 0 0 0 0 0 0 0 0 0
332 342 Monroe Ave & Leslie Ave 31087 38.820932 -77.053096 10 5 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
333 343 Mount Vernon Ave & Kennedy St 31088 38.833077 -77.059821 7 8 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
334 344 Court House Metro / 15th & N Uhle St 31089 38.890612 -77.084801 2 19 3 0 9 ... 0 0 0 0 0 0 0 0 0 0
335 345 Washington Adventist U / Flower Ave & Division St 32049 38.986743 -77.000035 8 7 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
336 346 6th & S Ball St 31090 38.864702 -77.048672 10 4 0 1 0 ... 0 0 0 0 0 0 0 0 0 0
337 347 McKinley St & Connecticut Ave NW 31315 38.964970 -77.075946 13 6 1 0 5 ... 0 0 0 0 0 0 0 0 0 0
338 348 15th & L St NW 31276 38.903810 -77.034931 7 16 4 1 10 ... 0 0 0 0 0 0 0 0 0 0
339 349 17th & G St NW 31277 38.898410 -77.039624 15 16 5 1 2 ... 0 0 0 0 0 0 0 0 0 0
340 350 Spring St & Second Ave 32050 38.997653 -77.034499 7 8 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
341 351 18th & R St NW 31278 38.912648 -77.041834 15 2 0 0 4 ... 1 0 0 0 0 0 0 0 0 0
342 352 S Joyce & 16th St S 31091 38.859254 -77.063275 11 4 0 0 0 ... 0 0 0 4 0 0 0 0 0 0
343 353 Union Market/6th St & Neal Pl NE 31517 38.908008 -76.996985 14 8 0 0 1 ... 0 0 0 0 0 0 0 0 0 0
344 354 N Nelson St & Lee Hwy 31092 38.895929 -77.105246 8 6 2 2 1 ... 0 0 0 0 0 0 0 0 0 0
345 355 21st St N & N Pierce St 31093 38.898984 -77.078317 7 7 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
346 356 Lee Hwy & N Kirkwood Rd 31094 38.895377 -77.097130 8 4 0 0 2 ... 0 0 0 0 0 0 0 0 0 0

347 rows × 136 columns


In [123]:
usage


Out[123]:
bike_id time_start time_end duration_mins station_start station_end cust_type temp date
0 W01412 2012-01-01 00:04:00 2012-01-01 00:11:00 7 7th & R St NW / Shaw Library 7th & T St NW Registered 0.370000 2012-01-01
1 W00524 2012-01-01 00:10:00 2012-01-01 00:29:00 19 Georgia & New Hampshire Ave NW 16th & Harvard St NW Casual 0.370000 2012-01-01
2 W00235 2012-01-01 00:10:00 2012-01-01 00:29:00 19 Georgia & New Hampshire Ave NW 16th & Harvard St NW Registered 0.370000 2012-01-01
3 W00864 2012-01-01 00:15:00 2012-01-01 00:23:00 8 14th & V St NW Park Rd & Holmead Pl NW Registered 0.370000 2012-01-01
4 W00995 2012-01-01 00:15:00 2012-01-01 00:23:00 8 11th & Kenyon St NW 7th & T St NW Registered 0.370000 2012-01-01
5 W00466 2012-01-01 00:17:00 2012-01-01 00:23:00 6 Court House Metro / 15th & N Uhle St Lynn & 19th St North Registered 0.370000 2012-01-01
6 W00525 2012-01-01 00:18:00 2012-01-01 00:47:00 29 37th & O St NW / Georgetown University 9th & Upshur St NW Registered 0.370000 2012-01-01
7 W00340 2012-01-01 00:22:00 2012-01-01 00:27:00 5 14th & V St NW 15th & P St NW Registered 0.370000 2012-01-01
8 W00466 2012-01-01 00:24:00 2012-01-01 00:33:00 9 Lynn & 19th St North 25th St & Pennsylvania Ave NW Registered 0.370000 2012-01-01
9 W00963 2012-01-01 00:25:00 2012-01-01 00:40:00 15 14th & V St NW L'Enfant Plaza / 7th & C St SW Registered 0.370000 2012-01-01
10 W01398 2012-01-01 00:29:00 2012-01-01 00:48:00 19 Tenleytown / Wisconsin Ave & Albemarle St NW Massachusetts Ave & Dupont Circle NW Registered 0.370000 2012-01-01
11 W00042 2012-01-01 00:30:00 2012-01-01 00:38:00 8 New York Ave & 15th St NW 21st & I St NW Registered 0.370000 2012-01-01
12 W00570 2012-01-01 00:32:00 2012-01-01 00:50:00 18 Metro Center / 12th & G St NW Massachusetts Ave & Dupont Circle NW Registered 0.370000 2012-01-01
13 W01463 2012-01-01 00:32:00 2012-01-01 00:50:00 18 Lamont & Mt Pleasant NW 14th & Rhode Island Ave NW Registered 0.370000 2012-01-01
14 W00535 2012-01-01 00:33:00 2012-01-01 00:50:00 17 Lamont & Mt Pleasant NW 14th & Rhode Island Ave NW Registered 0.370000 2012-01-01
15 W00494 2012-01-01 00:33:00 2012-01-01 00:50:00 17 Metro Center / 12th & G St NW Massachusetts Ave & Dupont Circle NW Registered 0.370000 2012-01-01
16 W00466 2012-01-01 00:33:00 2012-01-01 00:41:00 8 25th St & Pennsylvania Ave NW New York Ave & 15th St NW Registered 0.370000 2012-01-01
17 W00663 2012-01-01 00:33:00 2012-01-01 00:39:00 6 7th & T St NW Convention Center / 7th & M St NW Registered 0.370000 2012-01-01
18 W01052 2012-01-01 00:34:00 2012-01-01 00:42:00 8 14th & Rhode Island Ave NW 14th & V St NW Registered 0.370000 2012-01-01
19 W00174 2012-01-01 00:36:00 2012-01-01 00:52:00 16 17th & Corcoran St NW 17th & Corcoran St NW Registered 0.370000 2012-01-01
20 W01298 2012-01-01 00:37:00 2012-01-01 00:41:00 4 17th & Corcoran St NW Massachusetts Ave & Dupont Circle NW Registered 0.370000 2012-01-01
21 W01333 2012-01-01 00:39:00 2012-01-01 00:44:00 5 NaN 8th & H St NW Registered 0.370000 2012-01-01
22 W00697 2012-01-01 00:39:00 2012-01-01 00:42:00 3 Potomac & Pennsylvania Ave SE Potomac & Pennsylvania Ave SE Registered 0.370000 2012-01-01
23 W00260 2012-01-01 00:41:00 2012-01-01 00:49:00 8 4th & E St SW 5th & F St NW Registered 0.370000 2012-01-01
24 W00658 2012-01-01 00:45:00 2012-01-01 00:48:00 3 18th & M St NW 19th St & Pennsylvania Ave NW Registered 0.370000 2012-01-01
25 W00996 2012-01-01 00:45:00 2012-01-01 00:54:00 9 15th & P St NW NaN Registered 0.370000 2012-01-01
26 W00790 2012-01-01 00:46:00 2012-01-01 00:53:00 7 15th & P St NW NaN Registered 0.370000 2012-01-01
27 W01213 2012-01-01 00:48:00 2012-01-01 01:04:00 16 Massachusetts Ave & Dupont Circle NW 5th St & Massachusetts Ave NW Registered 0.370000 2012-01-01
28 W00981 2012-01-01 00:49:00 2012-01-01 00:55:00 6 Park Rd & Holmead Pl NW Columbia Rd & Belmont St NW Registered 0.370000 2012-01-01
29 W01270 2012-01-01 00:49:00 2012-01-01 00:59:00 10 17th & Corcoran St NW 16th & Harvard St NW Registered 0.370000 2012-01-01
... ... ... ... ... ... ... ... ... ...
2412494 W01430 2012-12-31 09:09:00 2012-12-31 09:20:00 11 15th St & Massachusetts Ave SE North Capitol St & F St NW Subscriber 0.215833 2012-12-31
2412495 W01486 2012-12-31 09:09:00 2012-12-31 09:28:00 19 Lincoln Park / 13th & East Capitol St NE 17th & Rhode Island Ave NW Subscriber 0.215833 2012-12-31
2412496 W00703 2012-12-31 09:08:00 2012-12-31 09:16:00 8 Braddock Rd Metro Market Square / King St & Royal St Subscriber 0.215833 2012-12-31
2412497 W00186 2012-12-31 09:08:00 2012-12-31 09:19:00 11 16th & Harvard St NW 24th & N St NW Subscriber 0.215833 2012-12-31
2412498 W00190 2012-12-31 09:08:00 2012-12-31 09:19:00 11 Columbia Rd & Georgia Ave NW Calvert St & Woodley Pl NW Subscriber 0.215833 2012-12-31
2412499 W20898 2012-12-31 09:08:00 2012-12-31 09:14:00 6 7th & R St NW / Shaw Library 5th & K St NW Subscriber 0.215833 2012-12-31
2412500 W20903 2012-12-31 09:08:00 2012-12-31 09:18:00 10 17th & Rhode Island Ave NW 10th & E St NW Subscriber 0.215833 2012-12-31
2412501 W00189 2012-12-31 09:08:00 2012-12-31 09:18:00 10 Adams Mill & Columbia Rd NW 24th & N St NW Subscriber 0.215833 2012-12-31
2412502 W20946 2012-12-31 09:07:00 2012-12-31 09:17:00 10 7th & F St NW / National Portrait Gallery 21st & I St NW Subscriber 0.215833 2012-12-31
2412503 W01438 2012-12-31 09:07:00 2012-12-31 09:12:00 5 11th & H St NE Columbus Circle / Union Station Subscriber 0.215833 2012-12-31
2412504 W00110 2012-12-31 09:07:00 2012-12-31 09:20:00 13 14th & V St NW 1st & M St NE Subscriber 0.215833 2012-12-31
2412505 W00122 2012-12-31 09:06:00 2012-12-31 09:08:00 2 N Quincy St & Wilson Blvd Central Library / N Quincy St & 10th St N Subscriber 0.215833 2012-12-31
2412506 W01397 2012-12-31 09:06:00 2012-12-31 09:13:00 7 Lincoln Park / 13th & East Capitol St NE Columbus Circle / Union Station Subscriber 0.215833 2012-12-31
2412507 W00078 2012-12-31 09:05:00 2012-12-31 09:27:00 22 10th & Monroe St NE Eastern Market / 7th & North Carolina Ave SE Subscriber 0.215833 2012-12-31
2412508 W00586 2012-12-31 09:05:00 2012-12-31 09:10:00 5 20th St & Florida Ave NW 20th & L St NW Subscriber 0.215833 2012-12-31
2412509 W01417 2012-12-31 09:05:00 2012-12-31 09:23:00 18 17th & Corcoran St NW Smithsonian / Jefferson Dr & 12th St SW Subscriber 0.215833 2012-12-31
2412510 W00282 2012-12-31 09:05:00 2012-12-31 09:15:00 10 5th & K St NW 13th & H St NE Subscriber 0.215833 2012-12-31
2412511 W00574 2012-12-31 09:04:00 2012-12-31 09:15:00 11 11th & H St NE Maryland & Independence Ave SW Subscriber 0.215833 2012-12-31
2412512 W00986 2012-12-31 09:04:00 2012-12-31 09:18:00 14 14th & R St NW 18th St & Pennsylvania Ave NW Subscriber 0.215833 2012-12-31
2412513 W20079 2012-12-31 09:02:00 2012-12-31 09:10:00 8 Lincoln Park / 13th & East Capitol St NE Columbus Circle / Union Station Subscriber 0.215833 2012-12-31
2412514 W01142 2012-12-31 09:02:00 2012-12-31 09:06:00 4 Thomas Circle 17th & K St NW / Farragut Square Subscriber 0.215833 2012-12-31
2412515 W20888 2012-12-31 09:02:00 2012-12-31 09:06:00 4 27th & Crystal Dr Crystal City Metro / 18th & Bell St Subscriber 0.215833 2012-12-31
2412516 W00025 2012-12-31 09:02:00 2012-12-31 09:11:00 9 14th & Rhode Island Ave NW 20th & E St NW Subscriber 0.215833 2012-12-31
2412517 W01059 2012-12-31 09:01:00 2012-12-31 09:07:00 6 15th & P St NW 17th & K St NW / Farragut Square Subscriber 0.215833 2012-12-31
2412518 W20913 2012-12-31 09:01:00 2012-12-31 09:12:00 11 13th & D St NE 7th & F St NW / National Portrait Gallery Subscriber 0.215833 2012-12-31
2412519 W00885 2012-12-31 09:01:00 2012-12-31 09:09:00 8 New Hampshire Ave & T St NW 22nd & I St NW / Foggy Bottom Subscriber 0.215833 2012-12-31
2412520 W00384 2012-12-31 09:01:00 2012-12-31 09:18:00 17 1st & M St NE US Dept of State / Virginia Ave & 21st St NW Subscriber 0.215833 2012-12-31
2412521 W20102 2012-12-31 09:00:00 2012-12-31 09:12:00 12 4th & East Capitol St NE Smithsonian / Jefferson Dr & 12th St SW Subscriber 0.215833 2012-12-31
2412522 W00746 2012-12-31 09:00:00 2012-12-31 09:11:00 11 21st & M St NW 13th St & New York Ave NW Subscriber 0.215833 2012-12-31
2412523 W20982 2012-12-31 09:00:00 2012-12-31 09:09:00 9 16th & Harvard St NW 17th & K St NW Subscriber 0.215833 2012-12-31

2412524 rows × 9 columns


In [138]:
station_counts = usage.groupby('station_start')['station_start'].count()

In [173]:
sc = DataFrame()
sc['rentals'] = station_counts.values / 366.0
sc['station'] = station_counts.index
sc


Out[173]:
rentals station
0 17.289617 10th & E St NW
1 10.418033 10th & Monroe St NE
2 71.243169 10th & U St NW
3 55.773224 10th St & Constitution Ave NW
4 35.185792 11th & H St NE
5 61.816940 11th & Kenyon St NW
6 10.183060 12th & Army Navy Dr
7 23.256831 12th & L St NW
8 3.554645 12th & Newton St NE
9 52.019126 13th & D St NE
10 42.765027 13th & H St NE
11 53.836066 13th St & New York Ave NW
12 51.997268 14th & D St NW / Ronald Reagan Building
13 33.185792 14th & D St SE
14 53.918033 14th & G St NW
15 71.054645 14th & Harvard St NW
16 68.147541 14th & R St NW
17 86.781421 14th & Rhode Island Ave NW
18 109.950820 14th & V St NW
19 27.346995 14th St & Spring Rd NW
20 9.904372 14th St Heights / 14th & Crittenden St NW
21 8.453552 15th & Crystal Dr
22 17.120219 15th & K St NW
23 6.210383 15th & N Scott St
24 135.016393 15th & P St NW
25 29.275956 15th St & Massachusetts Ave SE
26 95.270492 16th & Harvard St NW
27 118.980874 17th & Corcoran St NW
28 65.161202 17th & K St NW
29 54.939891 17th & K St NW / Farragut Square
... ... ...
155 5.215847 N Veitch & Key Blvd
156 70.775956 New Hampshire Ave & T St NW
157 67.437158 New York Ave & 15th St NW
158 86.937158 North Capitol St & F St NW
159 47.825137 Ohio Dr & West Basin Dr SW / MLK & FDR Memorials
160 77.516393 Park Rd & Holmead Pl NW
161 1.306011 Pennsylvania & Minnesota Ave SE
162 11.560109 Pentagon City Metro / 12th & S Hayes St
163 38.519126 Potomac & Pennsylvania Ave SE
164 0.360656 Potomac Ave & 35th St S
165 1.792350 Prince St & Union St
166 0.360656 Randle Circle & Minnesota Ave SE
167 21.669399 Rosslyn Metro / Wilson Blvd & Ft Myer Dr
168 11.961749 S Glebe & Potomac Ave
169 10.379781 S Joyce & Army Navy Dr
170 2.049180 Saint Asaph St & Pendleton St
171 47.669399 Smithsonian / Jefferson Dr & 12th St SW
172 27.980874 Tenleytown / Wisconsin Ave & Albemarle St NW
173 109.565574 Thomas Circle
174 49.109290 US Dept of State / Virginia Ave & 21st St NW
175 56.975410 USDA / 12th & Independence Ave SW
176 2.032787 Utah St & 11th St N
177 24.516393 Van Ness Metro / UDC
178 12.879781 Virginia Square Metro / N Monroe St & 9th St N
179 17.172131 Ward Circle / American University
180 3.065574 Washington Blvd & 10th St N
181 2.183060 Washington Blvd & 7th St N
182 10.065574 Wilson Blvd & Franklin Rd
183 7.879781 Wilson Blvd & N Edgewood St
184 5.155738 Wilson Blvd & N Oakland St

185 rows × 2 columns


In [174]:
stations2 = pd.merge(stations, sc, left_on='station', right_on='station')

In [181]:
stations2.columns.tolist()


Out[181]:
['id',
 'station',
 'terminal_name',
 'lat',
 'long',
 'no_bikes',
 'no_empty_docks',
 'fast_food',
 'parking',
 'restaurant',
 'convenience',
 'post_office',
 'bicycle_parking',
 'drinking_water',
 'recycling',
 'waste_basket',
 'waste_disposal',
 'cafe',
 'currency_exchange',
 'fountain',
 'ice_cream',
 'optician',
 'pharmacy',
 'tanning_salon',
 'car_sharing',
 'alcohol',
 'bank',
 'bar',
 'club',
 'embassy',
 'food_court',
 'government',
 'internal_kindergarten',
 'kindergarten',
 'place_of_worship',
 'post_box',
 'pub',
 'vending_machine',
 'fuel',
 'grave_yard',
 'public_building',
 'school',
 'fire_station',
 'nightclub',
 'atm',
 'hospital',
 'doctors',
 'theatre',
 'university',
 'clock',
 'parking_entrance',
 'police',
 'cultural_center',
 'stripclub',
 'marketplace',
 'dry_cleaner',
 'bicycle_repair_station',
 'office',
 'arts_centre',
 'library',
 'studio',
 'strip_club',
 'tourist',
 'veterinary',
 'community_centre',
 'compressed_air',
 'tutor',
 'clinic',
 'dentist',
 'bench',
 'cinema',
 'college',
 'parking_exit',
 'bar.restaurant',
 'car_rental',
 'coworking',
 'shelter',
 'bureau_de_change',
 'food_cart',
 'school..historic.',
 'border_control',
 'check_cashing',
 'nail_salon',
 'storage',
 'tax',
 'catering',
 'dojo',
 'tax_service',
 'bus_station',
 'hospital..historic.',
 'toilets',
 'marker',
 'social_facility',
 'telephone',
 'taxi',
 'building',
 'gym',
 'emergency_phone',
 'courthouse',
 'fitness_center',
 'townhall',
 'car_wash',
 'ev_charging',
 'recycling.waste_basket',
 'sign',
 'charging_station',
 'photography',
 'picnic_table',
 'nursing_home',
 'traffic_signals',
 'crossing',
 'motorway_junction',
 'bus_stop',
 'speed_camera',
 'service',
 'stop',
 'turning_circle',
 'elevator',
 'traffic_signals.bus_stop',
 'mini_roundabout',
 'footway',
 'street_lamp',
 'turning_loop',
 'hotel',
 'artwork',
 'information',
 'museum',
 'sculpture',
 'hostel',
 'picnic_site',
 'tour_guide',
 'attraction',
 'landmark',
 'motel',
 'guest_house',
 'gallery',
 'rentals']

In [150]:
from sklearn.linear_model import LinearRegression

In [314]:
model = LinearRegression()

In [315]:
plt.scatter(stations2.crossing, stations2.rentals)


Out[315]:
<matplotlib.collections.PathCollection at 0x7f3981d6f190>

In [317]:
model.fit(stations2[['crossing']], stations2.rentals)


Out[317]:
LinearRegression(copy_X=True, fit_intercept=True, normalize=False)

In [318]:
model.coef_


Out[318]:
array([ 0.46523832])

In [319]:
model.intercept_


Out[319]:
25.641599031542192

In [320]:
predicted = model.predict(stations2[['crossing']])

In [321]:
plt.scatter(stations2.rentals, predicted)


Out[321]:
<matplotlib.collections.PathCollection at 0x7f3981c75290>

In [164]:
model.singular_


Out[164]:
array([ 420.08785439])

In [165]:
from sklearn.metrics import r2_score

In [324]:
model.score(stations2[['crossing']], stations2.rentals)


Out[324]:
0.18651257991620984

In [329]:
plt.scatter(stations2.crossing, stations2.rentals)
x0 = min(stations2.crossing)
x1 = max(stations2.crossing)
y0 = model.predict(x0)
y1 = model.predict(x1)
plt.plot([x0,x1],[y0,y1])


Out[329]:
[<matplotlib.lines.Line2D at 0x7f3981a6b190>]

In [168]:
stations2.rentals


Out[168]:
0      1688
1      5113
2      3094
3      1986
4      4231
5      3799
6     13124
7      3727
8      8781
9      4378
10     4167
11    16014
12    40242
13    22625
14    34869
...
170     6266
171      386
172      241
173     1057
174     1448
175     5092
176     6328
177     9369
178      744
179      578
180      508
181     5654
182    22157
183    28560
184     7777
Name: rentals, Length: 185, dtype: int64

In [170]:
stations2.crossing


Out[170]:
0      0
1      0
2      0
3      0
4      0
5      0
6      0
7      0
8      0
9      1
10     0
11    47
12    14
13    20
14     6
...
170     91
171      0
172      0
173      4
174      1
175      0
176    122
177     16
178     15
179      2
180      0
181     19
182     47
183      7
184      1
Name: crossing, Length: 185, dtype: int64

In [182]:
quals = ['fast_food',
 'parking',
 'restaurant',
 'convenience',
 'post_office',
 'bicycle_parking',
 'drinking_water',
 'recycling',
 'waste_basket',
 'waste_disposal',
 'cafe',
 'currency_exchange',
 'fountain',
 'ice_cream',
 'optician',
 'pharmacy',
 'tanning_salon',
 'car_sharing',
 'alcohol',
 'bank',
 'bar',
 'club',
 'embassy',
 'food_court',
 'government',
 'internal_kindergarten',
 'kindergarten',
 'place_of_worship',
 'post_box',
 'pub',
 'vending_machine',
 'fuel',
 'grave_yard',
 'public_building',
 'school',
 'fire_station',
 'nightclub',
 'atm',
 'hospital',
 'doctors',
 'theatre',
 'university',
 'clock',
 'parking_entrance',
 'police',
 'cultural_center',
 'stripclub',
 'marketplace',
 'dry_cleaner',
 'bicycle_repair_station',
 'office',
 'arts_centre',
 'library',
 'studio',
 'strip_club',
 'tourist',
 'veterinary',
 'community_centre',
 'compressed_air',
 'tutor',
 'clinic',
 'dentist',
 'bench',
 'cinema',
 'college',
 'parking_exit',
 'bar.restaurant',
 'car_rental',
 'coworking',
 'shelter',
 'bureau_de_change',
 'food_cart',
 'school..historic.',
 'border_control',
 'check_cashing',
 'nail_salon',
 'storage',
 'tax',
 'catering',
 'dojo',
 'tax_service',
 'bus_station',
 'hospital..historic.',
 'toilets',
 'marker',
 'social_facility',
 'telephone',
 'taxi',
 'building',
 'gym',
 'emergency_phone',
 'courthouse',
 'fitness_center',
 'townhall',
 'car_wash',
 'ev_charging',
 'recycling.waste_basket',
 'sign',
 'charging_station',
 'photography',
 'picnic_table',
 'nursing_home',
 'traffic_signals',
 'crossing',
 'motorway_junction',
 'bus_stop',
 'speed_camera',
 'service',
 'stop',
 'turning_circle',
 'elevator',
 'traffic_signals.bus_stop',
 'mini_roundabout',
 'footway',
 'street_lamp',
 'turning_loop',
 'hotel',
 'artwork',
 'information',
 'museum',
 'sculpture',
 'hostel',
 'picnic_site',
 'tour_guide',
 'attraction',
 'landmark',
 'motel',
 'guest_house',
 'gallery']

In [183]:
stations2[quals]


Out[183]:
fast_food parking restaurant convenience post_office bicycle_parking drinking_water recycling waste_basket waste_disposal ... museum sculpture hostel picnic_site tour_guide attraction landmark motel guest_house gallery
0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
8 0 0 1 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
10 4 1 13 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
11 8 6 13 0 1 2 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
12 5 0 13 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
13 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
14 1 0 0 0 0 0 1 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
15 7 0 21 0 0 1 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
16 2 0 3 0 0 0 1 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
17 0 0 7 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
18 2 0 2 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
19 3 0 8 0 1 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
20 0 0 7 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
21 2 0 10 0 1 0 0 0 0 0 ... 1 0 0 0 0 0 0 0 0 0
22 3 1 0 0 0 0 1 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
23 3 8 6 1 1 0 0 2 2 0 ... 0 0 0 0 0 0 0 0 0 0
24 1 0 4 0 0 1 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
25 0 0 16 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
26 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
27 1 1 5 0 0 0 0 0 0 0 ... 0 0 1 0 0 0 0 0 0 0
28 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
29 6 0 6 0 2 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
155 5 0 11 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
156 1 1 2 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
157 0 0 0 0 0 0 1 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
158 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
159 0 2 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
160 2 2 3 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
161 1 0 0 0 1 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
162 9 5 15 0 2 0 0 0 0 0 ... 0 0 0 0 0 1 0 0 0 0
163 4 0 4 0 0 0 1 0 0 0 ... 0 0 1 0 0 0 0 0 0 0
164 5 10 14 0 1 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
165 10 7 17 0 0 2 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
166 0 1 1 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 1 0 0 0
167 1 1 4 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
168 0 3 1 0 1 0 0 0 0 0 ... 0 0 0 0 0 0 0 1 0 0
169 0 0 1 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 1 0 0 0
170 11 0 17 0 2 0 3 0 11 0 ... 0 0 0 0 0 0 0 0 0 0
171 1 0 1 0 1 0 0 0 0 0 ... 0 0 0 0 0 0 1 0 1 0
172 0 0 1 0 1 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
173 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
174 2 3 2 0 0 0 1 0 1 0 ... 0 0 0 0 0 0 1 0 0 0
175 0 0 2 0 0 0 1 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
176 5 2 16 0 1 4 0 0 0 0 ... 1 0 0 0 1 0 0 0 0 0
177 0 5 7 1 0 0 0 2 2 0 ... 0 0 0 0 0 0 0 0 0 0
178 2 0 3 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
179 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
180 0 0 0 0 0 0 0 1 0 0 ... 0 0 0 0 0 0 0 0 0 0
181 0 0 0 0 0 0 1 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
182 3 1 13 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
183 5 0 19 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
184 3 0 9 0 1 0 1 0 0 0 ... 0 0 0 0 0 0 0 0 0 0

185 rows × 129 columns


In [269]:
model.fit(stations2[quals], stations2.rentals)


Out[269]:
LinearRegression(copy_X=True, fit_intercept=True, normalize=False)

In [270]:
model.coef_


Out[270]:
array([  2.31238259e+00,  -2.09162716e-01,   5.70638043e-02,
        -6.31199792e+01,   1.95190000e+00,  -4.28939543e+00,
         5.50570714e+00,   1.88533354e+00,  -3.73790714e-01,
         1.42008832e+12,   2.45690477e+00,   6.89712732e+01,
         4.54372472e+00,  -4.58974500e+12,  -8.76784350e+11,
         5.22966429e+00,   2.20923388e+12,   4.69821366e+00,
         9.11396833e+00,  -3.02424836e+00,   3.22095906e+00,
        -3.74128373e+01,   2.79283540e+01,  -3.83757714e+01,
        -1.56526550e+01,   3.30970179e+11,   1.52153432e+00,
         3.03118706e+00,  -4.25396729e+00,   8.91869397e+00,
        -3.30970179e+11,  -3.06945776e-01,   3.24112848e+00,
         1.29117451e+01,   4.79684970e+00,  -1.95342874e+00,
        -3.43908538e+01,  -1.66489377e+01,   5.33308394e+00,
         5.00729922e+00,   1.14314737e+01,  -5.85254812e+00,
         1.48038067e+02,  -5.72457522e+00,  -1.28297722e+01,
         1.81806780e+02,  -3.64539795e-02,   3.78735020e-01,
        -6.61669786e+00,  -9.07681999e+00,   7.63297162e+01,
         6.02924776e+00,  -6.44980719e+00,  -1.93168091e+01,
         3.28999150e+01,   1.00170616e+01,   2.37682687e+01,
         5.39614411e+01,   1.56118503e+01,   5.24286788e+00,
         1.24324548e+01,  -1.81652083e+01,  -2.90451888e+00,
        -2.48456381e+01,  -2.69777516e+01,   1.75685443e+01,
        -2.49846859e+01,  -1.64232787e+01,  -1.70252108e+01,
        -2.01564006e+01,   4.58603899e+01,  -8.58072858e+01,
        -1.95520062e+01,   1.15954406e+01,  -1.21332142e+09,
         1.03742031e+09,   1.75901178e+08,   2.42664282e+09,
         3.65871192e+01,   3.16710973e+08,   8.96610437e+08,
         1.00410812e+02,   1.89600816e+09,  -8.39012997e+00,
         1.15469815e+01,   1.82915648e+08,  -1.82915649e+08,
        -1.10170225e+01,   1.92232287e+08,   1.16908906e+09,
         2.95376257e+01,  -8.30116685e+08,   1.57462941e+01,
        -4.95646829e+01,  -2.28191300e+08,  -1.24080288e+08,
        -5.40851325e+08,   2.07472903e+08,   1.45165877e+09,
        -5.18138811e+07,  -1.43941675e+09,  -9.74547798e+08,
         4.53232924e-02,   3.50320353e-01,  -1.08010730e+00,
        -6.28188165e-01,   4.05500421e+01,  -7.26614111e-05,
        -3.63282703e-01,  -4.95904220e+00,   3.31239296e+01,
         1.29390956e+01,  -3.53308652e+01,  -4.98695463e+00,
         1.74556818e+01,  -3.67941420e-38,   3.81918490e+00,
        -1.03265083e+00,  -1.82708260e+00,  -6.21699770e+00,
        -1.05534961e+00,  -9.44789700e+01,   1.64395081e+00,
        -2.19737904e+01,  -2.32887526e+00,  -1.81265465e+01,
        -2.13861653e+01,  -3.47988250e+01,   6.82556368e+00])

In [271]:
sorted(zip(quals, model.coef_), key=lambda pair: abs(pair[1]))


Out[271]:
[('turning_loop', -3.6794141970406044e-38),
 ('service', -7.2661411072072677e-05),
 ('stripclub', -0.036453979511101409),
 ('traffic_signals', 0.045323292383902661),
 ('restaurant', 0.057063804276298535),
 ('parking', -0.20916271565456279),
 ('fuel', -0.30694577623588026),
 ('crossing', 0.35032035328826178),
 ('stop', -0.36328270304114652),
 ('waste_basket', -0.37379071364648087),
 ('marketplace', 0.37873501976387269),
 ('bus_stop', -0.62818816474376848),
 ('artwork', -1.0326508328348512),
 ('sculpture', -1.055349610963237),
 ('motorway_junction', -1.0801072972248922),
 ('kindergarten', 1.5215343157739802),
 ('picnic_site', 1.6439508121958482),
 ('information', -1.8270826043517905),
 ('recycling', 1.8853335376308467),
 ('post_office', 1.9519000033741687),
 ('fire_station', -1.9534287391826326),
 ('fast_food', 2.3123825859929164),
 ('attraction', -2.3288752591969297),
 ('cafe', 2.4569047711466303),
 ('bench', -2.9045188778830866),
 ('bank', -3.0242483621963139),
 ('place_of_worship', 3.0311870593220367),
 ('bar', 3.2209590584083183),
 ('grave_yard', 3.2411284835388603),
 ('hotel', 3.8191849016691908),
 ('post_box', -4.2539672927277081),
 ('bicycle_parking', -4.2893954278294668),
 ('fountain', 4.5437247203495215),
 ('car_sharing', 4.6982136644581569),
 ('school', 4.7968497002485133),
 ('turning_circle', -4.9590421993984233),
 ('footway', -4.9869546287437005),
 ('doctors', 5.0072992191100028),
 ('pharmacy', 5.2296642892660135),
 ('tutor', 5.2428678846170698),
 ('hospital', 5.3330839430100374),
 ('drinking_water', 5.5057071396607924),
 ('parking_entrance', -5.7245752156573788),
 ('university', -5.852548124882528),
 ('arts_centre', 6.0292477573375605),
 ('museum', -6.2169976966123723),
 ('library', -6.4498071872797045),
 ('dry_cleaner', -6.6166978556683844),
 ('gallery', 6.8255636768020267),
 ('toilets', -8.3901299670123635),
 ('pub', 8.9186939723783762),
 ('bicycle_repair_station', -9.0768199864189469),
 ('alcohol', 9.113968329200592),
 ('tourist', 10.017061629344957),
 ('taxi', -11.017022518935242),
 ('theatre', 11.431473669352014),
 ('marker', 11.546981495434956),
 ('border_control', 11.595440551959859),
 ('clinic', 12.432454755357035),
 ('police', -12.82977223455701),
 ('public_building', 12.91174513524987),
 ('traffic_signals.bus_stop', 12.939095600857588),
 ('compressed_air', 15.611850327244339),
 ('government', -15.652654961042799),
 ('fitness_center', 15.746294120213699),
 ('car_rental', -16.423278655213206),
 ('atm', -16.648937656125828),
 ('coworking', -17.025210778498014),
 ('street_lamp', 17.455681795075609),
 ('parking_exit', 17.568544304421764),
 ('landmark', -18.12654647912408),
 ('dentist', -18.165208349838512),
 ('studio', -19.316809063064603),
 ('school..historic.', -19.55200618258224),
 ('shelter', -20.156400566210202),
 ('motel', -21.38616532038413),
 ('tour_guide', -21.973790371745984),
 ('veterinary', 23.768268710130055),
 ('cinema', -24.845638064929602),
 ('bar.restaurant', -24.984685892823297),
 ('college', -26.97775163762573),
 ('embassy', 27.928353952900622),
 ('emergency_phone', 29.537625681178369),
 ('strip_club', 32.899915015365437),
 ('elevator', 33.123929613777619),
 ('nightclub', -34.390853794588445),
 ('guest_house', -34.798825024097354),
 ('mini_roundabout', -35.330865160503173),
 ('catering', 36.587119227637089),
 ('club', -37.412837276475486),
 ('food_court', -38.375771411755075),
 ('speed_camera', 40.550042055220288),
 ('bureau_de_change', 45.860389889548308),
 ('townhall', -49.564682878390094),
 ('community_centre', 53.961441133416244),
 ('convenience', -63.119979238117573),
 ('currency_exchange', 68.971273197292973),
 ('office', 76.329716194712773),
 ('food_cart', -85.807285792555433),
 ('hostel', -94.478970001380929),
 ('bus_station', 100.41081247550332),
 ('clock', 148.03806663249338),
 ('cultural_center', 181.80678011146261),
 ('photography', -51813881.110550135),
 ('ev_charging', -124080287.90254819),
 ('storage', 175901178.44849953),
 ('social_facility', 182915647.97724181),
 ('telephone', -182915649.25015622),
 ('building', 192232287.02092257),
 ('sign', 207472903.13868797),
 ('car_wash', -228191300.16763979),
 ('dojo', 316710972.5236938),
 ('recycling.waste_basket', -540851325.07389224),
 ('courthouse', -830116685.19211257),
 ('tax_service', 896610436.71445286),
 ('nursing_home', -974547797.81045973),
 ('nail_salon', 1037420306.616001),
 ('gym', 1169089063.6262391),
 ('check_cashing', -1213321415.2861826),
 ('picnic_table', -1439416753.5382957),
 ('charging_station', 1451658770.1763897),
 ('hospital..historic.', 1896008160.7240911),
 ('tax', 2426642819.4090595),
 ('vending_machine', -330970178588.37762),
 ('internal_kindergarten', 330970178630.80286),
 ('optician', -876784350072.08716),
 ('waste_disposal', 1420088321190.0896),
 ('tanning_salon', 2209233876576.6016),
 ('ice_cream', -4589744997246.3535)]

In [272]:
predicted = model.predict(stations2[quals])

In [273]:
plt.scatter(predicted, stations2.rentals)


Out[273]:
<matplotlib.collections.PathCollection at 0x7f3982114b50>

In [275]:
len(stations2)


Out[275]:
185

In [189]:
from sklearn.cross_validation import train_test_split

In [190]:
x = stations2[quals]
y = stations2.rentals

In [191]:
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.33, random_state = 42)

In [192]:
model.fit(x_train, y_train)


Out[192]:
LinearRegression(copy_X=True, fit_intercept=True, normalize=False)

In [193]:
model.coef_


Out[193]:
array([  6.35230340e+00,  -1.20867488e+01,   8.50064336e-01,
         6.08071840e+01,  -9.77485960e+00,   1.55203205e+01,
         5.36812706e+00,   3.36232307e+00,   3.75811478e+00,
         2.62641788e-12,  -4.57347517e+00,  -1.42109811e-12,
        -6.09944021e+00,   1.89178059e-12,  -7.64892933e-13,
         6.86738858e+00,  -4.00205315e-13,  -3.49401199e+01,
         1.09376047e+02,   2.72552142e+00,   2.17903290e+00,
         6.37736311e+00,   5.31945505e+00,  -8.89060159e+00,
         4.77333926e+01,  -1.64213244e+01,  -7.11823339e-01,
         4.18374780e+00,  -1.23367236e+01,   5.75672915e+00,
        -1.64213244e+01,   5.96404651e+00,   7.99711386e+00,
         1.22546615e+01,   4.83222711e+00,  -1.63417586e+01,
        -4.14078402e+01,   2.83597236e+00,  -1.71393577e+00,
         2.07050190e+00,  -3.20651036e+01,  -5.83367328e+00,
         3.70515491e+01,   2.96624587e+01,  -3.37253337e+01,
         1.03361759e+02,  -2.05775251e+01,  -5.74547691e+01,
        -6.22590444e+01,  -5.31088171e+01,  -3.16504932e+01,
        -7.57235752e+01,  -1.17165937e+01,   1.01166435e+02,
         3.31013390e+01,  -3.38544386e+00,  -6.88251209e+00,
        -8.54526734e-14,   1.22042839e-13,  -2.81568026e-13,
        -4.49648716e+01,   3.65661192e+01,  -2.25727258e+00,
         3.13124345e+01,   2.17411198e+00,  -4.26869245e-14,
        -9.02214264e+01,   4.45731909e+01,   5.06510988e+01,
        -1.87173054e+01,  -1.53510369e+01,  -5.08051139e+01,
         1.98226144e+01,   4.22210024e+01,  -1.73516156e+01,
        -4.30730759e+01,  -4.30730759e+01,   3.75925995e+01,
        -2.44239585e+01,  -4.94637386e+01,  -4.94637386e+01,
         3.13048792e-14,  -7.71765445e-14,   3.85275327e+01,
         3.64712942e+01,   2.42679153e+01,   2.42679153e+01,
        -1.93896599e+01,  -5.08966900e-14,  -1.51884592e-14,
        -6.61416851e+01,  -1.82403559e-15,  -4.72933842e+01,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         4.81206391e-01,   2.50970485e-01,  -3.30930035e+00,
        -1.19528443e+00,   4.65335656e+01,   0.00000000e+00,
         4.90022014e-01,  -1.06257255e+01,   0.00000000e+00,
         3.06418145e+01,   2.61063218e+01,  -2.45722630e+01,
         1.93760331e+01,   0.00000000e+00,   1.29684509e+01,
         1.32102181e-02,  -4.56280561e+00,   1.99607880e+01,
         0.00000000e+00,   6.02886827e+01,  -1.71544351e+01,
         0.00000000e+00,   3.88235548e+00,  -2.93926752e+01,
         4.92032224e+00,   3.70945479e+01,   7.46857955e+01])

In [194]:
plt.scatter(y_train, model.predict(x_train))


Out[194]:
<matplotlib.collections.PathCollection at 0x7f3996743450>

In [195]:
plt.scatter(y_test, model.predict(x_test))


Out[195]:
<matplotlib.collections.PathCollection at 0x7f3996137610>

In [308]:
from sklearn.linear_model import Lasso
model = Lasso(alpha=100, max_iter=10000)

In [309]:
model.fit(x_train, y_train)


Out[309]:
Lasso(alpha=100, copy_X=True, fit_intercept=True, max_iter=10000,
   normalize=False, positive=False, precompute='auto', tol=0.0001,
   warm_start=False)

In [310]:
import numpy as np
np.round(model.coef_,1)


Out[310]:
array([ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,
        0. , -0. ,  0. ,  0. ,  0. ,  0. , -0. ,  0. ,  0. ,  0. ,  0. ,
        0. , -0. , -0. , -0. , -0. ,  0. ,  0. ,  0. , -0. , -0. ,  0. ,
        0. ,  0. , -0. ,  0. ,  0. , -0. , -0. ,  0. ,  0. ,  0. ,  0. ,
       -0. ,  0. ,  0. , -0. , -0. , -0. ,  0. ,  0. ,  0. ,  0. ,  0. ,
        0. ,  0. ,  0. ,  0. ,  0. , -0. , -0. ,  0. ,  0. ,  0. ,  0. ,
        0. ,  0. , -0. , -0. ,  0. , -0. , -0. ,  0. , -0. , -0. , -0. ,
       -0. ,  0. , -0. , -0. ,  0. ,  0. , -0. , -0. , -0. , -0. , -0. ,
        0. ,  0. , -0. ,  0. , -0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,
        0. ,  0. ,  0. ,  0.1,  0.4, -0. ,  0. ,  0. ,  0. , -0. , -0. ,
        0. ,  0. , -0. , -0. , -0. ,  0. ,  0. , -0. , -0. ,  0. ,  0. ,
       -0. ,  0. ,  0. , -0. , -0. , -0. , -0. ,  0. ])

In [311]:
sorted(zip(quals, model.coef_), key=lambda pair: abs(pair[1]))


Out[311]:
[('fast_food', 0.0),
 ('parking', 0.0),
 ('restaurant', 0.0),
 ('convenience', 0.0),
 ('post_office', 0.0),
 ('bicycle_parking', 0.0),
 ('drinking_water', 0.0),
 ('recycling', 0.0),
 ('waste_basket', 0.0),
 ('waste_disposal', 0.0),
 ('cafe', 0.0),
 ('currency_exchange', 0.0),
 ('fountain', -0.0),
 ('ice_cream', 0.0),
 ('optician', 0.0),
 ('pharmacy', 0.0),
 ('tanning_salon', 0.0),
 ('car_sharing', -0.0),
 ('alcohol', 0.0),
 ('bank', 0.0),
 ('bar', 0.0),
 ('club', 0.0),
 ('embassy', 0.0),
 ('food_court', -0.0),
 ('government', -0.0),
 ('internal_kindergarten', -0.0),
 ('kindergarten', -0.0),
 ('place_of_worship', 0.0),
 ('post_box', 0.0),
 ('pub', 0.0),
 ('vending_machine', -0.0),
 ('fuel', -0.0),
 ('grave_yard', 0.0),
 ('public_building', 0.0),
 ('school', 0.0),
 ('fire_station', -0.0),
 ('nightclub', 0.0),
 ('atm', 0.0),
 ('hospital', -0.0),
 ('doctors', -0.0),
 ('theatre', 0.0),
 ('university', 0.0),
 ('clock', 0.0),
 ('parking_entrance', 0.0),
 ('police', -0.0),
 ('cultural_center', 0.0),
 ('stripclub', 0.0),
 ('marketplace', -0.0),
 ('dry_cleaner', -0.0),
 ('bicycle_repair_station', -0.0),
 ('office', 0.0),
 ('arts_centre', 0.0),
 ('library', 0.0),
 ('studio', 0.0),
 ('strip_club', 0.0),
 ('tourist', 0.0),
 ('veterinary', 0.0),
 ('community_centre', 0.0),
 ('compressed_air', 0.0),
 ('tutor', 0.0),
 ('clinic', -0.0),
 ('dentist', -0.0),
 ('bench', 0.0),
 ('cinema', 0.0),
 ('college', 0.0),
 ('parking_exit', 0.0),
 ('bar.restaurant', 0.0),
 ('car_rental', 0.0),
 ('coworking', -0.0),
 ('shelter', -0.0),
 ('bureau_de_change', 0.0),
 ('food_cart', -0.0),
 ('school..historic.', -0.0),
 ('border_control', 0.0),
 ('check_cashing', -0.0),
 ('nail_salon', -0.0),
 ('storage', -0.0),
 ('tax', -0.0),
 ('catering', 0.0),
 ('dojo', -0.0),
 ('tax_service', -0.0),
 ('bus_station', 0.0),
 ('hospital..historic.', 0.0),
 ('toilets', -0.0),
 ('marker', -0.0),
 ('social_facility', -0.0),
 ('telephone', -0.0),
 ('taxi', -0.0),
 ('building', 0.0),
 ('gym', 0.0),
 ('emergency_phone', -0.0),
 ('courthouse', 0.0),
 ('fitness_center', -0.0),
 ('townhall', 0.0),
 ('car_wash', 0.0),
 ('ev_charging', 0.0),
 ('recycling.waste_basket', 0.0),
 ('sign', 0.0),
 ('charging_station', 0.0),
 ('photography', 0.0),
 ('picnic_table', 0.0),
 ('nursing_home', 0.0),
 ('motorway_junction', -0.0),
 ('bus_stop', 0.0),
 ('speed_camera', 0.0),
 ('service', 0.0),
 ('stop', -0.0),
 ('turning_circle', -0.0),
 ('elevator', 0.0),
 ('traffic_signals.bus_stop', 0.0),
 ('mini_roundabout', -0.0),
 ('footway', -0.0),
 ('street_lamp', -0.0),
 ('turning_loop', 0.0),
 ('hotel', 0.0),
 ('artwork', -0.0),
 ('information', -0.0),
 ('museum', 0.0),
 ('sculpture', 0.0),
 ('hostel', -0.0),
 ('picnic_site', 0.0),
 ('tour_guide', 0.0),
 ('attraction', -0.0),
 ('landmark', -0.0),
 ('motel', -0.0),
 ('guest_house', -0.0),
 ('gallery', 0.0),
 ('traffic_signals', 0.075089068191685704),
 ('crossing', 0.40866760950916631)]

In [312]:
model.score(x_test, y_test)


Out[312]:
0.047766946259890086

In [313]:
plt.scatter(y_train, model.predict(x_train))


Out[313]:
<matplotlib.collections.PathCollection at 0x7f3981e31c90>

In [284]:
plt.scatter(y_test, model.predict(x_test))


Out[284]:
<matplotlib.collections.PathCollection at 0x7f3981f92cd0>

In [226]:
np.corrcoef(y_test, model.predict(x_test))


Out[226]:
array([[ 1.        ,  0.33080653],
       [ 0.33080653,  1.        ]])

In [223]:
[pair for pair in zip(quals, model.coef_) if abs(pair[1]) > 0]


Out[223]:
[('fast_food', 0.32585579215001453),
 ('parking', -0.31998562989876017),
 ('restaurant', 1.1694703199160448),
 ('drinking_water', 3.0538714955277979),
 ('bank', -0.49970068518893634),
 ('kindergarten', -0.22387818527633283),
 ('place_of_worship', 1.8864249243605633),
 ('post_box', 4.9229928905839779),
 ('school', 1.7139294471103133),
 ('traffic_signals', -0.041145769122606125),
 ('crossing', 0.41392413896059321),
 ('stop', -0.90524069041916899),
 ('hotel', 11.248722454563387)]

In [224]:
r2_score(y_train, model.predict(x_train))


Out[224]:
0.6853024034515901

In [225]:
r2_score(y_test, model.predict(x_test))


Out[225]:
-0.21337330016917577

In [228]:
usage.cust_type.value_counts()


Out[228]:
Registered    1584150
Casual         421958
Subscriber     406416
dtype: int64

In [229]:
usage()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-229-6e7536b910c0> in <module>()
----> 1 usage()

TypeError: 'DataFrame' object is not callable

In [233]:
usage.groupby('cust_type')['duration_mins'].mean()


Out[233]:
cust_type
Casual        41.493881
Registered    12.091809
Subscriber    11.383536
Name: duration_mins, dtype: float64

In [234]:
usage


Out[234]:
bike_id time_start time_end duration_mins station_start station_end cust_type temp date
0 W01412 2012-01-01 00:04:00 2012-01-01 00:11:00 7 7th & R St NW / Shaw Library 7th & T St NW Registered 0.370000 2012-01-01
1 W00524 2012-01-01 00:10:00 2012-01-01 00:29:00 19 Georgia & New Hampshire Ave NW 16th & Harvard St NW Casual 0.370000 2012-01-01
2 W00235 2012-01-01 00:10:00 2012-01-01 00:29:00 19 Georgia & New Hampshire Ave NW 16th & Harvard St NW Registered 0.370000 2012-01-01
3 W00864 2012-01-01 00:15:00 2012-01-01 00:23:00 8 14th & V St NW Park Rd & Holmead Pl NW Registered 0.370000 2012-01-01
4 W00995 2012-01-01 00:15:00 2012-01-01 00:23:00 8 11th & Kenyon St NW 7th & T St NW Registered 0.370000 2012-01-01
5 W00466 2012-01-01 00:17:00 2012-01-01 00:23:00 6 Court House Metro / 15th & N Uhle St Lynn & 19th St North Registered 0.370000 2012-01-01
6 W00525 2012-01-01 00:18:00 2012-01-01 00:47:00 29 37th & O St NW / Georgetown University 9th & Upshur St NW Registered 0.370000 2012-01-01
7 W00340 2012-01-01 00:22:00 2012-01-01 00:27:00 5 14th & V St NW 15th & P St NW Registered 0.370000 2012-01-01
8 W00466 2012-01-01 00:24:00 2012-01-01 00:33:00 9 Lynn & 19th St North 25th St & Pennsylvania Ave NW Registered 0.370000 2012-01-01
9 W00963 2012-01-01 00:25:00 2012-01-01 00:40:00 15 14th & V St NW L'Enfant Plaza / 7th & C St SW Registered 0.370000 2012-01-01
10 W01398 2012-01-01 00:29:00 2012-01-01 00:48:00 19 Tenleytown / Wisconsin Ave & Albemarle St NW Massachusetts Ave & Dupont Circle NW Registered 0.370000 2012-01-01
11 W00042 2012-01-01 00:30:00 2012-01-01 00:38:00 8 New York Ave & 15th St NW 21st & I St NW Registered 0.370000 2012-01-01
12 W00570 2012-01-01 00:32:00 2012-01-01 00:50:00 18 Metro Center / 12th & G St NW Massachusetts Ave & Dupont Circle NW Registered 0.370000 2012-01-01
13 W01463 2012-01-01 00:32:00 2012-01-01 00:50:00 18 Lamont & Mt Pleasant NW 14th & Rhode Island Ave NW Registered 0.370000 2012-01-01
14 W00535 2012-01-01 00:33:00 2012-01-01 00:50:00 17 Lamont & Mt Pleasant NW 14th & Rhode Island Ave NW Registered 0.370000 2012-01-01
15 W00494 2012-01-01 00:33:00 2012-01-01 00:50:00 17 Metro Center / 12th & G St NW Massachusetts Ave & Dupont Circle NW Registered 0.370000 2012-01-01
16 W00466 2012-01-01 00:33:00 2012-01-01 00:41:00 8 25th St & Pennsylvania Ave NW New York Ave & 15th St NW Registered 0.370000 2012-01-01
17 W00663 2012-01-01 00:33:00 2012-01-01 00:39:00 6 7th & T St NW Convention Center / 7th & M St NW Registered 0.370000 2012-01-01
18 W01052 2012-01-01 00:34:00 2012-01-01 00:42:00 8 14th & Rhode Island Ave NW 14th & V St NW Registered 0.370000 2012-01-01
19 W00174 2012-01-01 00:36:00 2012-01-01 00:52:00 16 17th & Corcoran St NW 17th & Corcoran St NW Registered 0.370000 2012-01-01
20 W01298 2012-01-01 00:37:00 2012-01-01 00:41:00 4 17th & Corcoran St NW Massachusetts Ave & Dupont Circle NW Registered 0.370000 2012-01-01
21 W01333 2012-01-01 00:39:00 2012-01-01 00:44:00 5 NaN 8th & H St NW Registered 0.370000 2012-01-01
22 W00697 2012-01-01 00:39:00 2012-01-01 00:42:00 3 Potomac & Pennsylvania Ave SE Potomac & Pennsylvania Ave SE Registered 0.370000 2012-01-01
23 W00260 2012-01-01 00:41:00 2012-01-01 00:49:00 8 4th & E St SW 5th & F St NW Registered 0.370000 2012-01-01
24 W00658 2012-01-01 00:45:00 2012-01-01 00:48:00 3 18th & M St NW 19th St & Pennsylvania Ave NW Registered 0.370000 2012-01-01
25 W00996 2012-01-01 00:45:00 2012-01-01 00:54:00 9 15th & P St NW NaN Registered 0.370000 2012-01-01
26 W00790 2012-01-01 00:46:00 2012-01-01 00:53:00 7 15th & P St NW NaN Registered 0.370000 2012-01-01
27 W01213 2012-01-01 00:48:00 2012-01-01 01:04:00 16 Massachusetts Ave & Dupont Circle NW 5th St & Massachusetts Ave NW Registered 0.370000 2012-01-01
28 W00981 2012-01-01 00:49:00 2012-01-01 00:55:00 6 Park Rd & Holmead Pl NW Columbia Rd & Belmont St NW Registered 0.370000 2012-01-01
29 W01270 2012-01-01 00:49:00 2012-01-01 00:59:00 10 17th & Corcoran St NW 16th & Harvard St NW Registered 0.370000 2012-01-01
... ... ... ... ... ... ... ... ... ...
2412494 W01430 2012-12-31 09:09:00 2012-12-31 09:20:00 11 15th St & Massachusetts Ave SE North Capitol St & F St NW Subscriber 0.215833 2012-12-31
2412495 W01486 2012-12-31 09:09:00 2012-12-31 09:28:00 19 Lincoln Park / 13th & East Capitol St NE 17th & Rhode Island Ave NW Subscriber 0.215833 2012-12-31
2412496 W00703 2012-12-31 09:08:00 2012-12-31 09:16:00 8 Braddock Rd Metro Market Square / King St & Royal St Subscriber 0.215833 2012-12-31
2412497 W00186 2012-12-31 09:08:00 2012-12-31 09:19:00 11 16th & Harvard St NW 24th & N St NW Subscriber 0.215833 2012-12-31
2412498 W00190 2012-12-31 09:08:00 2012-12-31 09:19:00 11 Columbia Rd & Georgia Ave NW Calvert St & Woodley Pl NW Subscriber 0.215833 2012-12-31
2412499 W20898 2012-12-31 09:08:00 2012-12-31 09:14:00 6 7th & R St NW / Shaw Library 5th & K St NW Subscriber 0.215833 2012-12-31
2412500 W20903 2012-12-31 09:08:00 2012-12-31 09:18:00 10 17th & Rhode Island Ave NW 10th & E St NW Subscriber 0.215833 2012-12-31
2412501 W00189 2012-12-31 09:08:00 2012-12-31 09:18:00 10 Adams Mill & Columbia Rd NW 24th & N St NW Subscriber 0.215833 2012-12-31
2412502 W20946 2012-12-31 09:07:00 2012-12-31 09:17:00 10 7th & F St NW / National Portrait Gallery 21st & I St NW Subscriber 0.215833 2012-12-31
2412503 W01438 2012-12-31 09:07:00 2012-12-31 09:12:00 5 11th & H St NE Columbus Circle / Union Station Subscriber 0.215833 2012-12-31
2412504 W00110 2012-12-31 09:07:00 2012-12-31 09:20:00 13 14th & V St NW 1st & M St NE Subscriber 0.215833 2012-12-31
2412505 W00122 2012-12-31 09:06:00 2012-12-31 09:08:00 2 N Quincy St & Wilson Blvd Central Library / N Quincy St & 10th St N Subscriber 0.215833 2012-12-31
2412506 W01397 2012-12-31 09:06:00 2012-12-31 09:13:00 7 Lincoln Park / 13th & East Capitol St NE Columbus Circle / Union Station Subscriber 0.215833 2012-12-31
2412507 W00078 2012-12-31 09:05:00 2012-12-31 09:27:00 22 10th & Monroe St NE Eastern Market / 7th & North Carolina Ave SE Subscriber 0.215833 2012-12-31
2412508 W00586 2012-12-31 09:05:00 2012-12-31 09:10:00 5 20th St & Florida Ave NW 20th & L St NW Subscriber 0.215833 2012-12-31
2412509 W01417 2012-12-31 09:05:00 2012-12-31 09:23:00 18 17th & Corcoran St NW Smithsonian / Jefferson Dr & 12th St SW Subscriber 0.215833 2012-12-31
2412510 W00282 2012-12-31 09:05:00 2012-12-31 09:15:00 10 5th & K St NW 13th & H St NE Subscriber 0.215833 2012-12-31
2412511 W00574 2012-12-31 09:04:00 2012-12-31 09:15:00 11 11th & H St NE Maryland & Independence Ave SW Subscriber 0.215833 2012-12-31
2412512 W00986 2012-12-31 09:04:00 2012-12-31 09:18:00 14 14th & R St NW 18th St & Pennsylvania Ave NW Subscriber 0.215833 2012-12-31
2412513 W20079 2012-12-31 09:02:00 2012-12-31 09:10:00 8 Lincoln Park / 13th & East Capitol St NE Columbus Circle / Union Station Subscriber 0.215833 2012-12-31
2412514 W01142 2012-12-31 09:02:00 2012-12-31 09:06:00 4 Thomas Circle 17th & K St NW / Farragut Square Subscriber 0.215833 2012-12-31
2412515 W20888 2012-12-31 09:02:00 2012-12-31 09:06:00 4 27th & Crystal Dr Crystal City Metro / 18th & Bell St Subscriber 0.215833 2012-12-31
2412516 W00025 2012-12-31 09:02:00 2012-12-31 09:11:00 9 14th & Rhode Island Ave NW 20th & E St NW Subscriber 0.215833 2012-12-31
2412517 W01059 2012-12-31 09:01:00 2012-12-31 09:07:00 6 15th & P St NW 17th & K St NW / Farragut Square Subscriber 0.215833 2012-12-31
2412518 W20913 2012-12-31 09:01:00 2012-12-31 09:12:00 11 13th & D St NE 7th & F St NW / National Portrait Gallery Subscriber 0.215833 2012-12-31
2412519 W00885 2012-12-31 09:01:00 2012-12-31 09:09:00 8 New Hampshire Ave & T St NW 22nd & I St NW / Foggy Bottom Subscriber 0.215833 2012-12-31
2412520 W00384 2012-12-31 09:01:00 2012-12-31 09:18:00 17 1st & M St NE US Dept of State / Virginia Ave & 21st St NW Subscriber 0.215833 2012-12-31
2412521 W20102 2012-12-31 09:00:00 2012-12-31 09:12:00 12 4th & East Capitol St NE Smithsonian / Jefferson Dr & 12th St SW Subscriber 0.215833 2012-12-31
2412522 W00746 2012-12-31 09:00:00 2012-12-31 09:11:00 11 21st & M St NW 13th St & New York Ave NW Subscriber 0.215833 2012-12-31
2412523 W20982 2012-12-31 09:00:00 2012-12-31 09:09:00 9 16th & Harvard St NW 17th & K St NW Subscriber 0.215833 2012-12-31

2412524 rows × 9 columns


In [243]:
usage.pivot_table(index='station_start',columns='cust_type',values='duration_mins', aggfunc=[np.mean, len])


Out[243]:
mean len
cust_type Casual Registered Subscriber Casual Registered Subscriber
station_start
10th & E St NW 41.135981 13.620942 13.187406 2140 2187 2001
10th & Monroe St NE 61.479592 20.478459 18.060071 392 2855 566
10th & U St NW 28.409453 11.215585 13.621830 2137 19403 4535
10th St & Constitution Ave NW 49.939201 15.273347 13.993663 10033 8802 1578
11th & H St NE 30.741763 11.886388 11.452331 1123 9374 2381
11th & Kenyon St NW 27.233333 16.044243 12.304154 1530 17291 3804
12th & Army Navy Dr 54.793413 8.675048 9.145161 668 2625 434
12th & L St NW 25.910123 10.290961 10.116704 1057 3839 3616
12th & Newton St NE 39.505747 23.194589 20.746988 174 961 166
13th & D St NE 22.813467 10.750017 10.882142 1099 14877 3063
13th & H St NE 24.099152 12.985795 11.694639 1533 11545 2574
13th St & New York Ave NW 46.528479 11.355539 10.789943 3090 13810 2804
14th & D St NW / Ronald Reagan Building 44.916184 14.327581 12.817232 6383 9967 2681
14th & D St SE 25.685938 10.815371 10.295529 640 9381 2125
14th & G St NW 48.508418 12.338103 11.251860 4752 12159 2823
14th & Harvard St NW 27.204002 11.109028 10.911334 1799 19628 4579
14th & R St NW 28.874531 10.011749 9.154213 2399 18555 3988
14th & Rhode Island Ave NW 35.216134 9.978650 9.722463 4289 22389 5084
14th & V St NW 27.513299 10.297435 10.427645 3910 29546 6786
14th St & Spring Rd NW 27.384615 14.065569 14.192049 689 7534 1786
14th St Heights / 14th & Crittenden St NW 29.903890 19.529061 19.224852 437 2512 676
15th & Crystal Dr 58.238650 10.687047 8.770492 859 1930 305
15th & K St NW 39.251266 11.908923 10.995733 987 2701 2578
15th & N Scott St 58.842825 14.153296 10.582609 439 1259 575
15th & P St NW 32.210866 10.165773 10.023168 5117 35796 8503
15th St & Massachusetts Ave SE 22.936306 12.603889 11.995041 628 7869 2218
16th & Harvard St NW 27.474347 10.733680 12.376230 2222 26547 6100
17th & Corcoran St NW 31.624260 9.710947 9.416127 3545 32437 7565
17th & K St NW 42.182776 11.706077 12.111197 2752 17212 3885
17th & K St NW / Farragut Square 44.081863 11.790673 10.856051 2834 14002 3272
... ... ... ... ... ... ...
N Veitch & Key Blvd 91.932584 10.203782 21.437681 267 952 690
New Hampshire Ave & T St NW 27.191775 9.678763 8.623602 2456 16203 7245
New York Ave & 15th St NW 46.336511 12.692574 13.538862 8496 13304 2882
North Capitol St & F St NW 39.287762 12.097782 11.971372 4396 21415 6008
Ohio Dr & West Basin Dr SW / MLK & FDR Memorials 46.160996 20.524957 17.405018 13460 3486 558
Park Rd & Holmead Pl NW 26.458057 11.825150 11.606043 1812 21264 5295
Pennsylvania & Minnesota Ave SE 53.220779 15.118971 13.611111 77 311 90
Pentagon City Metro / 12th & S Hayes St 49.951507 12.623560 8.790210 763 3039 429
Potomac & Pennsylvania Ave SE 25.059322 11.473429 10.755662 1062 10519 2517
Potomac Ave & 35th St S 33.387097 NaN 7.673267 31 NaN 101
Prince St & Union St 60.337931 20.515152 17.166667 290 132 234
Randle Circle & Minnesota Ave SE 42.096774 21.511111 20.272727 31 90 11
Rosslyn Metro / Wilson Blvd & Ft Myer Dr 55.387314 16.582403 14.730252 2081 4660 1190
S Glebe & Potomac Ave 60.059250 12.188932 11.337535 827 2837 714
S Joyce & Army Navy Dr 63.433198 13.881135 12.935556 741 2608 450
Saint Asaph St & Pendleton St 48.837349 11.609023 9.527716 166 133 451
Smithsonian / Jefferson Dr & 12th St SW 59.502651 18.853372 15.790530 12450 3751 1246
Tenleytown / Wisconsin Ave & Albemarle St NW 48.534996 15.004086 14.174622 1243 7343 1655
Thomas Circle 37.328482 10.369796 9.650986 6253 26493 7355
US Dept of State / Virginia Ave & 21st St NW 41.628404 13.282895 12.711883 3746 11552 2676
USDA / 12th & Independence Ave SW 54.576732 14.542038 13.054174 8054 10990 1809
Utah St & 11th St N 37.464646 8.117470 11.274760 99 332 313
Van Ness Metro / UDC 50.388010 17.260931 17.678218 1201 6358 1414
Virginia Square Metro / N Monroe St & 9th St N 54.369208 10.607486 8.519859 669 2912 1133
Ward Circle / American University 51.595392 15.364833 13.686275 1085 4180 1020
Washington Blvd & 10th St N 49.552980 10.221691 8.875648 302 627 193
Washington Blvd & 7th St N 35.950413 9.833680 10.289340 121 481 197
Wilson Blvd & Franklin Rd 55.369466 9.925439 13.926569 655 2280 749
Wilson Blvd & N Edgewood St 43.236486 11.132682 7.491833 592 1741 551
Wilson Blvd & N Oakland St 37.368030 11.011597 12.581489 269 1121 497

185 rows × 6 columns


In [252]:
mins = usage[['duration_mins']]

In [250]:
casual = usage.cust_type == 'Casual'

In [246]:
from sklearn.linear_model import LogisticRegression

In [247]:
model = LogisticRegression()

model.fit(mins, casual)


In [254]:
model.coef_


Out[254]:
array([[ 0.05867854]])

In [255]:
model.intercept_


Out[255]:
array([-2.61445367])

In [256]:
predicted = model.predict(mins)

In [258]:
predicted


Out[258]:
array([False, False, False, ..., False, False, False], dtype=bool)

In [259]:
casual


Out[259]:
0     False
1      True
2     False
3     False
4     False
5     False
6     False
7     False
8     False
9     False
10    False
11    False
12    False
13    False
14    False
...
2412509    False
2412510    False
2412511    False
2412512    False
2412513    False
2412514    False
2412515    False
2412516    False
2412517    False
2412518    False
2412519    False
2412520    False
2412521    False
2412522    False
2412523    False
Name: cust_type, Length: 2412524, dtype: bool

In [260]:
df = DataFrame({"predicted" : predicted, "actual" : casual})

In [261]:
df


Out[261]:
actual predicted
0 False False
1 True False
2 False False
3 False False
4 False False
5 False False
6 False False
7 False False
8 False False
9 False False
10 False False
11 False False
12 False False
13 False False
14 False False
15 False False
16 False False
17 False False
18 False False
19 False False
20 False False
21 False False
22 False False
23 False False
24 False False
25 False False
26 False False
27 False False
28 False False
29 False False
... ... ...
2412494 False False
2412495 False False
2412496 False False
2412497 False False
2412498 False False
2412499 False False
2412500 False False
2412501 False False
2412502 False False
2412503 False False
2412504 False False
2412505 False False
2412506 False False
2412507 False False
2412508 False False
2412509 False False
2412510 False False
2412511 False False
2412512 False False
2412513 False False
2412514 False False
2412515 False False
2412516 False False
2412517 False False
2412518 False False
2412519 False False
2412520 False False
2412521 False False
2412522 False False
2412523 False False

2412524 rows × 2 columns


In [262]:
df.predicted.value_counts()


Out[262]:
False    2283741
True      128783
dtype: int64

In [263]:
df.actual.value_counts()


Out[263]:
False    1990566
True      421958
dtype: int64

In [265]:
df[~df['actual']]['predicted'].value_counts()


Out[265]:
False    1974712
True       15854
dtype: int64

In [ ]: